Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 为什么MVC actionlink渲染不正确?_Html_Asp.net Mvc_Html Helper_Html.actionlink - Fatal编程技术网

Html 为什么MVC actionlink渲染不正确?

Html 为什么MVC actionlink渲染不正确?,html,asp.net-mvc,html-helper,html.actionlink,Html,Asp.net Mvc,Html Helper,Html.actionlink,我要通过这个: <%: Html.ActionLink("Edit", "EditCRMRequest", "CRM", new { Id = item.Id })%> 错误代码为: 参数字典包含的参数“Id”为空 方法的不可为Null的类型“System.Int32” 中的“System.Web.Mvc.ActionResult EditCRMRequest(Int32)” 'apricarEvent.Controllers.CRM.CRMController'。可选参数 必须是

我要通过这个:

<%: Html.ActionLink("Edit", "EditCRMRequest", "CRM", new { Id = item.Id })%>
错误代码为:

参数字典包含的参数“Id”为空 方法的不可为Null的类型“System.Int32” 中的“System.Web.Mvc.ActionResult EditCRMRequest(Int32)” 'apricarEvent.Controllers.CRM.CRMController'。可选参数 必须是引用类型、可为null的类型或声明为 可选参数。参数名称:参数

如果我在浏览器中显式编写此代码,则效果良好:

http://something.com/CRM/EditCRMRequest?Id=3
正确的方法:

<%: Html.ActionLink("Edit", "EditCRMRequest", "CRM", new { Id = item.Id },null)%>
如果您像上面那样编写,
Lenght=3
表示“CRM”。控制器名称表现为RouteValue

正确的方法是:

Html.ActionLink(string text, string action, string controller, object routeValues, object htmlAttributes)
正确的方法:

<%: Html.ActionLink("Edit", "EditCRMRequest", "CRM", new { Id = item.Id },null)%>
如果您像上面那样编写,
Lenght=3
表示“CRM”。控制器名称表现为RouteValue

正确的方法是:

Html.ActionLink(string text, string action, string controller, object routeValues, object htmlAttributes)

就像下面提到的答案一样,如果您查看正在使用的方法重载,那么它需要的是htmlAttributes,而不是RouteValue。这就是为什么在查询字符串上得到?length=3的原因。就像下面提到的答案一样,如果您查看正在使用的方法重载,它期望的是HtmlatAttributes,而不是RouteValue。这就是为什么在查询字符串上得到?length=3。