Thursday, November 9, 2017
MVC ActionLink will not Accept Markup (easy fix!)
I needed to make a button that included a glyphicon. The glyphicon looked like this:
<i class="fa fa-plus"></i>
If you use this in @Html.ActionLink() you'll see the markup in your page, not the glyphicon.
There is a way around this:
Replace your @Html.ActionLink() with this...
<a href="@Url.Action("Index","Customers",new { CompanyID = Model.UniqueId }, null)" class="btn btn-warning"><i class="fa fa-plus"></i></a>
Yeah, it's a lot more text, but Url.Action() does most of the heavy lifting. Another requirement I had was that the QA website URL includes a folder. i.e. in development the URL is http://localhost:34238/ and in QA it's http://website.com/projectname/. This prevents me from just hard coding the link to /Customers/Index... Url.Action takes care of this as well.
Bryan Valencia is a contributing editor and founder of Visual Studio Journey. He owns and operates Software Services, a web design and hosting company in Manteca, California.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment