ASP.NET MVC - Applying Html.ActionLink to an existing href - asp.net-mvc

Basically, I'm just trying to change the href attribute to be the result of the ActionLink:
#Html.ActionLink("Home", "Index", "Dashboard", new { }, new { #class = "nav-link active" })
<a class="nav-link active" href="index.html">
<div class="sb-nav-link-icon"><i class="fas fa-home"></i></div>
Home
</a>
If I replaced the index.html with #Html.ActionLink("Home", "Index", "Dashboard"), then what happens is the HTML is not formed correctly.
Any suggestions would be appreciated.
Thanks!

#Url.Action("Index", "Dashboard"), sorry this can be closed. Of course as soon as I ask I find the answer.

I guess that this code will work as you want it to. You don't have to use #Html.ActionLink
<a class="nav-link active" href="Dashboard/Index">
<div class="sb-nav-link-icon"><i class="fas fa-home"></i></div>
Home
</a>

Related

#Html.ActionLink to a <a href="#Url.Action()>

the doubt is this:
I have to use a <a></a>, because of the notation I'm using in all my app, I'm working in ASP.NET MVC. So, I have an href="#Url.Action with class="btn btn-primary", a simple button as this:
<a href="#Url.Action("Manage", "Account")" class="btn btn-primary text-right">
<span class="glyphicon glyphicon-circle-arrow-left" aria-hidden="true"></span> Administrar
</a>
(That was an example of the estructure that I need)
But now I have to convert this:
#Html.ActionLink(User.Identity.GetUserName(), "Manage", "Account",
routeValues: null, htmlAttributes: new { title = "Administrar" })
to that estructure. The fact is, I don't know where to put the routevalues and User.Identity.GetUserName(). I don't need the htmlAttributes neither the title.
Please help me and thanks a lot.
For title, you just simple use title="Administrar", so when you hover mouse on the button/link, it'll still show Administrar in tool-tip.
For Username, you will need # sign at the front.
<a href="#Url.Action("Manage", "Account")" class="btn btn-primary text-right"
title="Administrar">
<i class="fa fa-arrow-circle-left" aria-hidden="true"></i>
#User.Identity.GetUserName()
</a>
Another suggestion is not to use Bootstrap's glyphicon, because they won't be available in next version anymore. Instead, you might want to consider using Font Awesome.
It should be:
<a href="#Url.Action("Manage", "Account")" class="btn btn-primary text-right">
<span class="glyphicon glyphicon-circle-arrow-left" aria-hidden="true"></span>
#User.Identity.GetUserName()
</a>
routevalues will be next parameter in Url.Action method if you need it.
Like this:
Url.Action("Manage", "Account", new { id = 1 })
I suppose you have Html.Actionlink like bellow
#Html.ActionLink("Home", "index", null, new { #class = "btn btn-primary" })
all you need to do is to write it like this
<a class="brand" href="#Url.Action("index","Home")"> </a>
and you are done!

Adding custom html into Html.MenuItem link

I use Html.MenuItem helper in asp .net mvc. I want to use html inside link instead of text only. The helper below:
#Html.MenuItem("Announcement", "Index", "Announcement")
generates in html =>
<li> Announcement </li>
but I want to generate an html like =>
<li>
<a href="/Announcement">
<i class="icon-announcement"></i>
<span>Announcement</span>
</a>
</li>
How can I do that?
You can't do that immediately, because the HTML gets stripped if you pass it in as the parameter.
I suggest you do something like the following:
<li>
<a href='#Url.Action("Announcement", "Index")'>
<i class="icon-announcement"></i>
<span>Announcement</span>
</a>
</li>

Why won't a #Html.ActionLink render inside an li tag?

My question is simple. I have an unordered list <ul>... </ul> with a bunch of <li>...</li> tags. Inside those <li> tags I have some #Html.ActionLink(...) that just won't render. Am I doing something fundimentally wrong here? This is my code:
<div id="menuDiv">
<ul id="myMenu">
<li >#Html.ActionLink("Dashboard", "Index", new { sender = "AgentScoreCareReport"})</li>
</ul>
</div>
Try this
<li >#Html.ActionLink("Dashboard", "Index",
new { sender = "AgentScoreCareReport"},null)</li>
This turned out to be a CSS problem. It's been fixed.
Thanks everyone who made suggestions!

Links not opening with left click

I am having a bit of a problem with my site, i am trying to add a simple link to an external site, but i can't get the link to open without right clicking and selecting open link.
This is the piece of code
<div class="brick1 odd">
<a href="https://www.google.co.uk/" class="nav-item"</a>
<div class="nav-hover"></div>
<i class="li_shop"></i>
<span>Shop now</span>
</a>
</div>
I know it's most likely something simple but i can't seem to pin it down
Thanks
Aha! The problem is because you are trying to link from an http to an https!
Your anchor tag needs to override the click handler:
<a href="https://www.google.co.uk/" class="nav-item" onclick="return !window.open(this.href,'WINDOW_NAME');" >
Should fix it!
But I would still fix the nesting.
try properly nesting everything, like so:
<div class="brick1 odd">
<a href="https://www.google.co.uk/" class="nav-item" onclick="return !window.open(this.href,'WINDOW_NAME');">
<div class="nav-hover">
<i class="li_shop">
<span>Shop now</span>
</i>
</div>
</a>
</div>
Syntax error
<a href="https://www.google.co.uk/" class="nav-item">
<div class="nav-hover"></div>
<i class="li_shop"></i>
<span>Shop now</span>
</a>

ASP.NET MVC: generating action link with custom html in it

How can I generate action link with custom html inside.
Like following:
<a href="http://blah-blah/.....">
<span class="icon"/>
New customer
</a>
You can use the UrlHelper class :
<a href="<% =Url.Action("Create","Customers") %>">
<span class="icon"/> New customer
</a>
The MSDN link is here : http://msdn.microsoft.com/en-us/library/system.web.mvc.urlhelper.aspx
For newer versions of .net,
replace
href="<% =Url.Action("Create","Customers") %>"
with
href="#Url.Action("Create","Customers")"
to give something like
<a href="#Url.Action("Create","Customers")">
<span class="icon"/> New customer
</a>

Resources