Razor语法可防止在ActionLink中转义HTML

Ada*_*dam 12 c# razor asp.net-mvc-3

我有一个ASP MVC 3网站,我们正试图在动作链接中加入一些样式.

我希望html是类似的<a href="/somepath/someaction"><span class="someclass">some text</span> some more text</a>但我无法弄清楚如何告诉Razor <span>正确渲染它.

到目前为止我尝试过的:

@Html.ActionLink("<span class="someclass">some text</span> some more text", SomeAction, SomeController);
Run Code Online (Sandbox Code Playgroud)

导致链接看起来像: <span class="someclass">some text</span> some more text

@Html.ActionLink("<text><span class="someclass">some text</span></text> some more text", SomeAction, SomeController);
Run Code Online (Sandbox Code Playgroud)

导致链接看起来像: <text><span class="someclass">some text</span></text> some more text

@Html.ActionLink(<text>"<span class="someclass">some text</span> some more text"</text>, SomeAction, SomeController);
Run Code Online (Sandbox Code Playgroud)

导致编译错误.

思考?

SLa*_*aks 24

ActionLink方法不能采用HTML.

你需要制作一个普通的<a>标签,并@Url.Action(...)用于href.