Brian Liang
Brian Liang

Reputation: 7774

Custom Razor HTML Markup

I'm looking into creating a custom helper to do the following:

<a href="controller/"> <strong>Item</strong> </a>

I know that @Html.RouteLink(...) will handle the anchor for you but I wanted to insert the "<strong> </strong>" tag to it.

Other than to write a custom method to manipulate the string, I was wondering if there was a cleaner solution to this?

Thanks

Upvotes: 0

Views: 185

Answers (3)

MoXplod
MoXplod

Reputation: 3852

I would create an anchor with a class so you put your styling in CSS instead of making the html heavier and define the style of the page.

Upvotes: 0

Iridio
Iridio

Reputation: 9271

You can write your extension of ActionLink. Look at this article. the author wrote about extending to have Img link, but you can get the idea and info to do your own extension

Upvotes: 0

Roland Mai
Roland Mai

Reputation: 31077

Two options:

  1. Use new { @class = "myClass" } as parameters to the helper and apply css to the link to make it bold.
  2. Manually create the anchor's URL (<a href="@Url.RouteUrl(...)) to the path you want using Url.RouteUrl

Upvotes: 2

Related Questions