I want to do autopostback to dropdownlist.
My form on view:
@using (Html.BeginForm("Index", "Model", FormMethod.Post))
{
@(Html.Telerik().DropDownList()
.Name("ddlBrands")
.BindTo((IEnumerable<SelectListItem>)ViewData["brands"])
.ClientEvents(events => events
.OnChange("onDropDownListChange")
)
)
<input type="submit" value="OK" />
<table style="margin:15px; margin-left:0px;">
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.FullModel)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id=item.ModelID }) |
@Html.ActionLink("Delete", "Delete", new { id=item.ModelID })
</td>
</tr>
}
</table>
}
and javascript:
<script type="text/javascript">
function onDropDownListChange(e) {
SimpleAjaxRequest('/Model/Index', e.value);
}
function SimpleAjaxRequest(url, requestData) {
return $.ajax(
{
type: 'POST',
url: url,
async: true,
data: { ddlBrands: requestData },
dataType: "json",
traditional: true
});
}
</script>
I send Post data via Ajax from Index view to server and after manipulation data I need update data on my form. how I can do it? I’m try redirect to POST action
[HttpPost]
public ActionResult Index(string ddlBrands)
{
SetBrandItems();
return RedirectToAction("Index", "Model", new {ddlBrands = ddlBrands});
}
after calling GET action
public ActionResult Index(int? ddlBrands)
{
SetBrandItems();
List<Model> m = dm.GetModelsByBrandId(ddlBrands).ToList();
return View(m);
}
but my page not refresh and url not change and data not updating…
anybody can help me?
The DropDownList change event is ajax operaiton. I think you can not redirect in server-side. But you can add a rediect in the ajax callback.
eg: