m having problem in passing parameter to controller action, i have done the following
Url.Action("Scho开发者_高级运维olDetails","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..
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"]
.
You have to define your default route in Global.asax
to:
routes.MapRoute(
"Default",
"Home",
new { Controller = "Home", action = "Index", schoolId = UrlParameter.Optional }
and change your Action
to Url.Action("SchoolDetails","School",new{schoolId =item.SchoolId})
.
精彩评论