Is it possible to use an ActionLink containing an element?

寵の児 提交于 2019-12-01 03:01:05

Just use @Url.Action instead:

<a href="@Url.Action("Page","Site", new { id = Model.Id, @Type = "test" })">
 <span class="box5">Click anywhere in this box</span> </a>

There's a hack you can use to work around the limitation

@Html.Raw(
     Html
        .ActionLink("-replace-me-", .....)
        .ToString()
        .Replace(
              "-replace-me-", 
              @"<span class=""box5"">Click anywhere in this box</span>"))

it's not elegant, but it does the job

Html.ActionLink is just a plain old Extension Method to the HtmlHelper object.

You can create your own custom extension methods for HtmlHelper as well, and they're pretty simple to do and will save you tons of time.

You can not specify a html tag inside actionlink, but I can suggest you two solutions: 1 extend the actionlink with your function. So you can also implement actionlink that generate href with other htmal tag inside (img or span like in your case)

2 using the url.content in the href. It's like your actual workaround but better because you use the rules you have defined in the global.asax instead of using "magic string"

Just Write <span> </span> and in between the span use the @html>ActionLink Method It will work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!