Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC3 Razor - Html.ActionLink style

I'm trying to set the style of an action link like so:

  <text><p>Signed in as @Html.ActionLink(Context.User.Identity.Name,"Index",new { Controller="Account", @style="text-transform:capitalize;" })</p> 

I'd expect this to be rendered as

<p>Signed in as <a href="Index" style="text-transform:capitalize;">MyName</a></p> 

However, what's generated is

<p>Signed in as <a href="/Account?style=text-transform%3Acapitalize%3B">MyName</a></p> 

with the style appended to the url instead. What am I doing wrong?

like image 830
3Dave Avatar asked Jan 03 '11 20:01

3Dave


1 Answers

Here's the signature.

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

What you are doing is mixing the values and the htmlAttributes together. values are for URL routing.

You might want to do this.

@Html.ActionLink(Context.User.Identity.Name, "Index", "Account", null,       new { @style="text-transform:capitalize;" }); 
like image 102
Daniel A. White Avatar answered Sep 30 '22 12:09

Daniel A. White