I'm working with MVC4 Razor and converting a site that was pure html and trying to figure out how to get the quivilant via the @Html.ActionLink
this is one of the links in my html markup
<a href="/bots.html"><span><span>Learn More</span></span></a>
if I use @Html.ActionLink("Learn More", "Bots", "Home") I Get
<a href="/Home/Bots">Learn More</a>
I need it to be
<a href="/Home/Bots"><span><span>Learn More</span></span></a>
I can hard code <a href="/Home/Bots"><span><span>Learn More</span></span></a> into the page but I would like to use the actionlink as its easier to maintain
ok I'm liking this second option but where would you put the class ? under models ? or under the root of the Project ? I'm very new to the whole asp.net thing and this started out as a webforms project but I'm liking the razor far better
JackieMay
Member
2 Points
29 Posts
Html.Actionlink
Dec 21, 2012 02:16 AM|LINK
I'm working with MVC4 Razor and converting a site that was pure html and trying to figure out how to get the quivilant via the @Html.ActionLink
this is one of the links in my html markup
<a href="/bots.html"><span><span>Learn More</span></span></a>
if I use @Html.ActionLink("Learn More", "Bots", "Home") I Get
<a href="/Home/Bots">Learn More</a>
I need it to be
<a href="/Home/Bots"><span><span>Learn More</span></span></a>
I can hard code <a href="/Home/Bots"><span><span>Learn More</span></span></a> into the page but I would like to use the actionlink as its easier to maintain
CPrakash82
All-Star
18286 Points
2842 Posts
Re: Html.Actionlink
Dec 21, 2012 02:39 AM|LINK
<a href="@Url.Action("Bots", "Home")"><span><span>Learn More</span></span></a>
JackieMay
Member
2 Points
29 Posts
Re: Html.Actionlink
Dec 21, 2012 02:52 AM|LINK
Thankyou that solved more than one issue
quantt
Member
215 Points
38 Posts
Re: Html.Actionlink
Dec 21, 2012 02:54 AM|LINK
Hi JackieMay,
You will be have 2 options :
- Not custom actionlink
<a href="@Url.Action("Bots","Home")"><span><span>Learn More</span></span></a>-Custom ActionLink
public static class MyHtmlExtensions { public static MvcHtmlString MyActionLink(this HtmlHelper html, string action, string controller,string text) { var url = UrlHelper.GenerateContentUrl("~/" + controller + "/" + action); var myBuilder= new TagBuilder("a"); myBuilder.Attributes.Add("href", url); myBuilder.InnerHtml=string.Format("<span><span>{0}</span></span>",text); return new MvcHtmlString(myBuilder.ToString()); } }Quan Truong
Please, click 'Mark as answer' if you think my answer really help you. Thanks
JackieMay
Member
2 Points
29 Posts
Re: Html.Actionlink
Dec 21, 2012 03:03 AM|LINK
ok I'm liking this second option but where would you put the class ? under models ? or under the root of the Project ? I'm very new to the whole asp.net thing and this started out as a webforms project but I'm liking the razor far better