I have a drop down list that, when changed, should refresh the model for the view. Here is the controller:
public ActionResult Index()
{
//do something totally awesome
}
[HttpPost]
public ActionResult Index(int user)
{
//do something even more awesome with the new value selected from the drop down list
}
The relevant part of the View:
<div id="selectuser" class="user-input">@Html.DropDownListFor(x => x.SelectedUser, Model.Users)</div>
and the jQuery to handle the drop down list changing:
$(function () {
$('#selectuser select').change(function () {
$.post('@Url.Action("Index", "Home")', { user: $(this).val() }, function (result) {
});
});
});
It appears that everything is working, except the jQuery part. Evidently, the UrlAction(...) isn't right. When a user changes the selection, this is the URL MVC tries to load: http://localhost:5555/@Url.Action%28%22Index%22,%20%22Home%22%29
I was expecting MVC to route to the HttpPost Index action in the controller when a selection changed. Why didn't it? How do I fix it?
I'm a total noob at this - your help is greatly appreciated.