Html.ActionLink() 内に HTML を配置してもリンク テキストがない場合はどうすればよいですか? 質問する

Html.ActionLink() 内に HTML を配置してもリンク テキストがない場合はどうすればよいですか? 質問する

質問が2つあります。

  1. Html.ActionLink()MVC ビューで使用するときにリンク テキストを表示しないようにするにはどうすればいいのか疑問に思っています(実際は ですSite.Master)。

There is not an overloaded version that does not allow link text, and when I try passing in just a blank string, the compiler tells me it needs a non-empty string.

How can I fix this?

  1. I need to put <span> tags within the anchor tag, but it's not working with Html.ActionLink();. I'd like to see the following output:

    Span text

How can I put tags inside of the anchor tag in ASP.NET MVC?

ベストアンサー1

Instead of using Html.ActionLink you can render a url via Url.Action

<a href="<%= Url.Action("Index", "Home") %>"><span>Text</span></a>
<a href="@Url.Action("Index", "Home")"><span>Text</span></a>

And to do a blank url you could have

<a href="<%= Url.Action("Index", "Home") %>"></a>
<a href="@Url.Action("Index", "Home")"></a>

おすすめ記事