Click here to Skip to main content
15,885,038 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The following function GetProject is called on change of the dropdown in the view.

Javascript

XML
<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();
           
            /* Conditions:
             * @All openended questions in a project
             * */
            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
Posted

1 solution

Check whether value is null before assigning it to selectedValue
to check whether value is null refer this


http://stackoverflow.com/questions/6003884/how-do-i-check-for-null-values-in-javascript[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900