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
, notschoolId
in theUrl.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.aController/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 withRequest.QueryString["id"]
.