为什么MVC actionlink不能正确渲染? [英] Why is MVC actionlink not rendering correctly?
问题描述
<%:Html.ActionLink(Edit,EditCRMRequest,CRM ,new {Id = item.Id})%>
而我正在浏览器中:
http://something.com/CRM/EditCRMRequest?Length=3
与错误代码:
参数字典包含参数'Id'为空的条目
不可空在
'ApricaCRMEvent.Controllers.CRM.CRMController'中为方法
'System.Web.Mvc.ActionResult EditCRMRequest(Int32)'键入'System.Int32'。可选参数
必须是引用类型,可为空类型,或者声明为
可选参数。参数名称:参数
如果我在浏览器中明确地写这个,它可以正常工作:
http://something.com/CRM/EditCRMRequest?Id=3
<正确的方法:
<%:Html.ActionLink (Edit,EditCRMRequest,CRM,new {Id = item.Id},null)%>
没有像这样的重载方法:
Html.ActionLink(string text,string action,string controller,object routeValues)
如果像上面这样写, Lenght = 3
代表CRM。控制器名称的行为如routeValues
正确的方法是:
Html。 ActionLink(string text,string action,string controller,object routeValues,object htmlAttributes)
I am passing this :
<%: Html.ActionLink("Edit", "EditCRMRequest", "CRM", new { Id = item.Id })%>
and I am getting in browser :
http://something.com/CRM/EditCRMRequest?Length=3
with Error Code :
The parameters dictionary contains a null entry for parameter 'Id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult EditCRMRequest(Int32)' in 'ApricaCRMEvent.Controllers.CRM.CRMController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters
If I explicitly write this in browser it works fine:
http://something.com/CRM/EditCRMRequest?Id=3
Correct way:
<%: Html.ActionLink("Edit", "EditCRMRequest", "CRM", new { Id = item.Id },null)%>
No overload method like this:
Html.ActionLink(string text, string action, string controller, object routeValues)
If you write like above, Lenght=3
is represent "CRM". Controller name behave as routeValues
Correct method is:
Html.ActionLink(string text, string action, string controller, object routeValues, object htmlAttributes)
这篇关于为什么MVC actionlink不能正确渲染?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!