I am trying to allow user to choose a sort method from a dropdown list.I am not fully certain how to accomplish this. Here are my beginnings.
RestaurantVm.cs:
I am trying to allow user to choose a sort method from a dropdown list.I am not fully certain how to accomplish this. Here are my beginnings.
RestaurantVm.cs:
// Not sure how populate this
public SelectList SortMethods { get; set; }
public string SelectedMethod { get; set; }
RestaurantsController:
public ActionResult sortedRestaurants( RestaurantVm mv )
{
string SelectedValue = mv.SelectedMethod;
switch (SelectedValue)
{
case "Name":
SortByName()
default:
break;
}
return View(mv);
}
In the view:
@Html.DropDownListFor(m => m.SelectedMethod, Model.SortMethods, "Select a method")
Jquery Code:
$(document).ready(function(){
$("#ddlId").change(function(){
$.ajax({
type:'POST',
url:'url.action('Controller Name','Action Method Name')'
data:{id:$('#ddlId').val()},
sucess:{
}
});
})
})
The problem:
I don't know how to populate selectList properly, I am not sure how to properly use jquery method to call action.