MVC 3 exception: The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc

a 夏天 提交于 2019-12-06 13:41:49

This error is thrown if you attempt to call this controller action and you do not specify the id either in the path portion or as query string parameter. Since your controller action takes an id as parameter you should make sure that you always specify this parameter.

Make sure that when you are requesting this action you have specified a valid id in the url:

http://example.com/somecontroller/agency/123

If you are generating an anchor, make sure there's an id:

@Html.ActionLink("click me", "agency", new { id = "123" })

If you are sending an AJAX request, also make sure that the id is present in the url.

If on the other hand the parameter is optional, you could make it a nullable integer:

public ActionResult Agency(int? id)

but in this case you will have to handle the case where the parameter value is not specified.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!