I'm trying to Update a part of my view, using Ajax and Partial view, but I got some trouble : This my controller :
[HttpPost]
public ActionResult Index(StatModel model)
{
if (ModelState.IsValid)
{
switch (model.SelectedStat)
{
case "agR" :
List<agR> agentr = nbrAGbyR(model.SelectedItemsRegion.ToList());
return PartialView("_agByR", agentr);
case "demandeR":
List<demandeR> demander = nbrDMbyR(model.SelectedItemsRegion.ToList());
return PartialView("_dmByR", demander);
... Other case option ....
}
}
..
return PartialView();
}
This is my Index.cshtml View :
@model pfebs0.Models.StatModel
...
<div class="row">
<div class="col-md-6">
<h2>Statistique Par region</h2>
@using (Ajax.BeginForm("Index", new AjaxOptions
{
UpdateTargetId = "result",
InsertionMode = InsertionMode.InsertAfter,
HttpMethod = "POST"
}))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
@Html.ListBoxFor(m=>m.SelectedItemsRegion, (ViewBag.REGIONID as SelectList))
@Html.DropDownListFor(m=> m.SelectedStat, Model.statList)
<p>
<input type="submit" value="Create" />
</p>
}
...
<div class="col-md-10">
<h2>Resultat</h2>
<div id="result"></div>
</div>
...
And this an Example Of my partialView :
@model List<pfebs0.Models.agR>
@using GridMvc.Html
<h3 id="agR">Statistique Agent generaux par region</h3>
@Html.Grid(Model).Named("agR").Columns(columns =>
{
columns.Add(model => model.nbr)
.Sortable(false)
.Titled("Nombre des Agent's");
columns.Add(model => model.regionName)
.Sortable(true)
.Titled("Nom du region");
}).WithPaging(10)
When I click on submit button nothing happend, what's the problem here?