The following function
GetProject is called on change of the dropdown in the view.
Javascript
<script>
function GetProject(projId) {
var selectedText = projId.options[projId.selectedIndex].innerHTML;
var selectedValue = projId.value;
var url = '@Url.Action("OpenEndedDetails", "ResponseController", new { @projId = "projId" }, null);
url = url.replace('projId', encodeURIComponent(selectedValue));
alert(url);
window.location.href = url;
}
</script>
ResponseController
public ActionResult OpenEndedDetails(int projId)
{
ResponseContext feedback = new ResponseContext();
List<Response> feedbacks = feedback.Responses.Where(resp => resp.Answer.Equals("0") && resp.ProjectID == projId).ToList();
return View(feedbacks);
}
Error:
The parameters dictionary contains a null entry for parameter 'projId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult OpenEndedDetails(Int32)' in 'SmartAdminMvc.Controllers.ResponseController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
ProjId is a primary key of type int. I don't know how to get rid of this exception. I want the Url.Action to load my entire view, with the value that i pass from the dropdown.
I might have made some major blunders with code. Kindly correct it.
Please help me as i am stuck with this issue for long.
Thanks