简体   繁体   中英

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

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

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

我会用类创建一个锚,所以你把你的样式放在CSS中,而不是让html更重,并定义页面的样式。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM