Asp.net-mvc – html.actionlink doesn’t passing parameter to controller action

asp.netasp.net-mvc

m having problem in passing parameter to controller action, i have done the following


    Url.Action("SchoolDetails","School",new{id=item.SchoolId})

and my controller action follows


    public ActionResult SchoolDetails(string schoolId,_ASI_School schoolDetail)
    {
            schoolDetail = SchoolRepository.GetSchoolById(schoolId);
            return View(schoolDetail);
    }

i dn't know why the schoolId above in action is getting null..

Best Answer

Your parameter is named id, not schoolId in the Url.Action method call. The names of the parameters in the html,in your controller's action and in the route definition must match. Also you must have this parameter in your route. For example if you use the default route a.k.a Controller/Action/{id}, rename the parameter in your action to id. If the parameter is not found in your route it will be moved to query-string parameter and you can access it in the action with Request.QueryString["id"].

Related Topic