Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.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
C# 带有routevalue的MVC Razor Actionlink问题_C#_Asp.net_Asp.net Mvc_Razor - Fatal编程技术网

C# 带有routevalue的MVC Razor Actionlink问题

C# 带有routevalue的MVC Razor Actionlink问题,c#,asp.net,asp.net-mvc,razor,C#,Asp.net,Asp.net Mvc,Razor,我正在使用以下代码尝试actionlink: @Html.ActionLink("Home", "List", "Product", new { @class = horizontal ? "btn btn-default btn-sm" : "btn btn-block btn-default btn-lg" }) 但是,这会给我一个错误,除非我在html属性之前为RouteValue添加null。我不明白为什么会这样。这可能是mvc版

我正在使用以下代码尝试actionlink:

@Html.ActionLink("Home", "List", "Product",
    new {
        @class = horizontal ? "btn btn-default btn-sm" :
            "btn btn-block btn-default btn-lg"
    })
但是,这会给我一个错误,除非我在html属性之前为RouteValue添加null。我不明白为什么会这样。这可能是mvc版本的问题,或者我在某处引用了错误的dll


请帮忙。我遵循了Adam Freeman(Apress)的Sportsstore示例应用程序,他的代码没有routevalues的null值,显然是有效的

的有一些重载。您需要的是:


您正试图传递htmlAttributes的匿名
对象。要匹配签名,您的
routeValue
需要包含一个值(在本例中为null)。没有三个字符串和一个对象作为参数的重载,因此您会得到一个错误。

我猜这是错误的重载-看不到版本问题-从来没有一个重载只接受
linkText
actionName
controllerName
routevalue
(您可能没有正确地遵循示例,或者示例错误)OP包含控制器名称,因此需要its。
public static MvcHtmlString ActionLink(
    this HtmlHelper htmlHelper,
    string linkText,
    string actionName,
    string controllerName,
    object routeValues,
    object htmlAttributes
)