In My MVC 4 Application i have a partial view. That contain a drop down list. when i change the drop down list, that value has to send the controller. But it is sending null value. How can i send the drop down value to controller.
Thanks in advance.
Here is my code:
Drop down list Code :
<select name="ddSortByPrice" id="ddSort" onchange="this.form.submit(getComboA(this))")">
<option>-- Sort By Price --</option>
@foreach (var item in ViewBag.SortingStatus){
<option value="@item.Value">@item.Text</option>
}</select>
Javascript Code:
function getComboA(sel) {
var value = sel.options[sel.selectedIndex].value;
$.post('<%= Url.Action("WhatsNewSortBy","RouteValue") %>', new { value: val }, function(result) {
// TODO: handle the success
});
}
Controller code:
public ActionResult WhatsNewSortBy(string value)
{
return RedirectToAction("WhatsNewOffers", "Product", new { @sortBy = value});
}
var value = sel.options[sel.selectedIndex].value;However your postback is using the value of an undefined variablevalIs this a typo in your example code, or is that typo in your actual code as well?$.post()you are specifically settingvalue: val, which doesn't exist.