ASP.NET, I have a controller with this GET method:
public ActionResult Index(String state, String searchNumber, String searchCustomer, int? page)
{
}
in the view I call it in this way:
$("#btnSearch").click(function (event) {
var params = {
state: '@ViewBag.State',
searchNumber: $('input[name=searchNumber]').val(),
searchCustomer: $('input[name=searchCustomer]').val()
};
var url = window.location.href + "/Index/?" + jQuery.param(params);
window.location.href = url;
});
where the @ViewBag.State is a String received from the controller while the other fields are from texboxes.
Here a real example of the url value:
"http://localhost:49396/Orders/Index/?state=Opened&searchNumber=17&searchCustomer="
In the controller Index function the searchNumber variable is set to "17" but state to null.
Why the first one is not recognized?
console.log('@ViewBag.State')in your script and inspect the result. Is it what you expect?