Common question is: how to call Controller.Action and send it some parameters on standard html event (like onblur or onclick).
I`m using Asp.Net MVC3.
Original situation:
I have DropDownList on my page like this:
@Html.DropDownList("DropDownList", ViewBag.selectList as IEnumerable<SelectListItem>)
I dont want to use @Html.DropDownListFor because it means I should save some additional information in my model which is unlikely.
What I need: to call DropDownListSelectionChanged(int moduleId) action of the same controller SelectedIndexChanged event and to send Selected Item Value to this action.
Please, help.
It’s pretty simple. You can either use the built in
Ajax.BeginFormin MVC land, or you can use jQuery to send the request. I’ll show you the jQuery example (simply because jQuery makes ajax stupidly easy and it’s easy to write):Then your action method would look like this: