0

How can I add here a class name?

 Html.ActionLink(
       item.Name, 
       "GetProducts", 
       "Products", 
        new { CityName = item.CityName.UnderScore(), CategoryName = item.Name.UnderScore() },
        null);

Thanks.

0

1 Answer 1

2

Use this Html.ActionLink overload method

public static MvcHtmlString ActionLink(
    this HtmlHelper htmlHelper,
    string linkText,
    string actionName,
    string controllerName,
    RouteValueDictionary routeValues,
    IDictionary<string, Object> htmlAttributes
)

your example

Html.ActionLink(
   item.Name, 
   "GetProducts", 
   "Products", 
    new { CityName = item.CityName.UnderScore(), CategoryName = item.Name.UnderScore() },
    new { @class="some_class" });
Sign up to request clarification or add additional context in comments.

1 Comment

Using the @ symbol is how you use any C# keyword as something other than a keyword. Most times people will just try to name it something else but in cases like this where it HAS to be called class (due to it mapping to an HTML attribute), prefixing it with @ is your only option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.