Home Ask Login Register

Developers Planet

Your answer is one click away!

user3816366 February 2016

MVC Razor Actionlink issue with routevalue

I am trying an actionlink with the following code :

@Html.ActionLink("Home", "List", "Product",
    new {
        @class = horizontal ? "btn btn-default btn-sm" :
            "btn btn-block btn-default btn-lg"
    })

However this gives me an error unless I add null for the routevalues before the html attributes. I can't figure out why this is so. Could this be a mvc version issue or perhaps I'm referencing the wrong dll somewhere ?

Please assist. I was following the Sportsstore example application by Adam Freeman(Apress) and his code doesn't have the null for routevalues and apparently works.

Answers


Erwin Rooijakkers February 2016

There are a few overloads for ActionLink. The one you need is this one:

public static MvcHtmlString ActionLink(
    this HtmlHelper htmlHelper,
    string linkText,
    string actionName,
    string controllerName,
    object routeValues,
    object htmlAttributes
)

You are trying to pass an anonymous object of htmlAttributes. To match the signature your routeValues needs to contain a value (null in this case). There is no overload with three strings and one object as a parameter, therefore you get an error.

Post Status

Asked in February 2016
Viewed 2,773 times
Voted 8
Answered 1 times

Search




Leave an answer


Quote of the day: live life