Struggling with evaluating a hidden field in JavaScript (ASP MVC4). I've set up a model in my View with a hidden input for one of the properties.
@Html.HiddenFor(mdl => mdl.FilterByUser, new { @id = "filterByUserId" })
Within my Helper, I have a SearchBox that triggers a search when the enter key is pressed.
$("#search-box").keydown(function (event) {
var keypressed = event.keyCode || event.which;
if (keypressed == 13) {
var searchValue = $("#search-box").val();
var filterByUser = $("#filterByUserId").val();
debugger;
window.location = "?searchValue=" + searchValue + "&filterByUser=" + filterByUser;
}
});
The issue arises with the variable filterByUser, which only contains a value when the Developer Tools are on and the browser halts at the 'debugger' statement. Without the tools open, an error message stating "The parameters dictionary contains a null entry for parameter 'filterByUser' of non-nullable type 'System.Boolean'" pops up.
In contrast, the other variable, searchValue, evaluates without any problem.
Any suggestions on how to resolve this dilemma would be greatly appreciated. Thank you, Daniel