Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.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
Razor MVC4动态创建的ActionLink意外工作_Razor_Asp.net Mvc 4 - Fatal编程技术网

Razor MVC4动态创建的ActionLink意外工作

Razor MVC4动态创建的ActionLink意外工作,razor,asp.net-mvc-4,Razor,Asp.net Mvc 4,我用的是MVC4和剃刀 当我动态创建ActionLink并希望有人能解释原因时,我得到了意想不到的结果:问题是当我将null作为htmlAttribute传递时,URL生成正确。但是,当我传入一个值时,URL的Area部分就乱七八糟了 <li> @Html.ActionLink(link.LinkText, link.ActionName, link.ControllerName, rvd,link.ActionName.Equals(currentAction) &&

我用的是MVC4和剃刀

当我动态创建ActionLink并希望有人能解释原因时,我得到了意想不到的结果:问题是当我将null作为htmlAttribute传递时,URL生成正确。但是,当我传入一个值时,URL的Area部分就乱七八糟了

<li> @Html.ActionLink(link.LinkText, link.ActionName, link.ControllerName, rvd,link.ActionName.Equals(currentAction) && link.ControllerName.Equals(currentController)? new { @class = "currentMenuItem" }:null)</li>

http://localhost:48000/Accounts/Forum/TopicsGrid?Count=2&Keys=System.Collections.Generic.Dictionary%602%2BKeyCollection%5BSystem.String%2CSystem.Object%5D&Values=System.Collections.Generic.Dictionary%602%2BValueCollection%5BSystem.String%2CSystem.Object%5D
  • @Html.ActionLink(link.LinkText、link.ActionName、link.ControllerName、rvd、link.ActionName.Equals(currentAction)和&link.ControllerName.Equals(currentController)?新建{@class=“currentMenuItem”}:null)
  • http://localhost:48000/Accounts/Forum/TopicsGrid?Count=2&Keys=System.Collections.Generic.Dictionary%602%2BKeyCollection%5BSystem.String%2CSystem.Object%5D&Values=System.Collections.Generic.Dictionary%602%2BValueCollection%5BSystem.String%2CSystem.Object%5D
    当我将null作为htmlAttribute传递时,它是正确的:

    <li> @Html.ActionLink(link.LinkText, link.ActionName, link.ControllerName, rvd, null)</li>   
    
    http://localhost:48000/Forums/Forum/TopicsGrid/1
    
  • @Html.ActionLink(link.LinkText、link.ActionName、link.ControllerName、rvd、null)
  • http://localhost:48000/Forums/Forum/TopicsGrid/1
    ActionLink()
    a
    字典,对象
    重载。

    由于您的最后一个参数是
    对象
    ,routeValues参数也被解释为objetc,因此它读取
    RouteValudDictionary
    类的属性。

    感谢您的回复-不确定我是否理解。我正在向htmlAttribute参数传递一个值。“rvd”参数是RouteValueDictionary参数。@Greg:是的。如果我显式地传递新的{@class=“currentMenuItem”}作为htmlAttribute,它就会工作,但显然这会突出显示所有链接。那么为什么我使用“link.ActionName.Equals(currentAction)…”失败了吗?@Greg:传递一个字典而不是一个对象。我尝试了这个,但仍然不起作用:var myDictionary=new dictionary();添加(“类”、“当前菜单项”)
  • @Html.ActionLink(link.LinkText、link.ActionName、link.ControllerName、rvd、myDictionary)