NoWar
NoWar

Reputation: 37632

How to convert complex HTML <a> tag to ASP .NET MVC 3 ActionLink?

By design I have

<a href="#"><span><strong>ABOUT US</strong></span></a>

There is CSS which does some special things with span tag.

But I need to convert it into

@Html.ActionLink("ABOUT US", "About", "Home") 

So I have in some way to put span strong into @Html.ActionLink

Thank you for any clue!

Upvotes: 0

Views: 727

Answers (4)

StanK
StanK

Reputation: 4770

Alternatively, change your css so that any <a> tags with a class "strong" have the style you want applied to them.

if your css is like this:

strong {
   /* whatever */
}

change it to

strong, a.strong {
   /* whatever */
}

Then you can style up your links just by adding class="strong" like this

<a href="#" class="strong">ABOUT US<a>

to get the same style applied to the link.

Then you can acheive the same HTML by going

@Html.ActionLink("ABOUT US", "About", "Home", null, new { @class = "strong"} ) ;

which will render a link with the class "strong"

Upvotes: 0

wnascimento
wnascimento

Reputation: 1959

Use Url.Action to generate only url, not (a) link tag. See the follow link.

http://www.netrostar.com/MVCOutgoingUrls

Upvotes: 0

wycleffsean
wycleffsean

Reputation: 1377

Instead of using the Html.ActionLink helper, I would do it the following way:

<a href="@Url.Action("About", "Home")"><span><strong>ABOUT US</strong></span></a>

Upvotes: 9

shennyL
shennyL

Reputation: 2794

You should try create your own custom html helper, here is some clue for you: Is it possible to use an ActionLink containing an element?

Hope this help :)

Upvotes: 1

Related Questions