#Html.ActionLink to a <a href="#Url.Action()> - asp.net-mvc

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!

Related

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

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>

How to use glyphicon in HTML helpers? [duplicate]

This question already has answers here:
ASP.NET Actionlink with glyphicon and text with different font
(10 answers)
Closed 5 years ago.
I have this anchor element that displays glyphicon and some style:
<a href="#" class="btn btn-3d btn-xlg btn-reveal btn-brown">
<i class="glyphicon glyphicon-arrow-right"></i>
<span>REVEAL EXTRA LARGE</span>
</a>
In my project I use HTML helper to create anchor elements.
I have this html helper to create anchor element:
#Html.ActionLink(item.Name, "About", "Home", item, new { #class = "btn btn-3d btn-xlg btn-reveal btn-brown" })
But I don't know how to add <i class="glyphicon glyphicon-arrow-right"></i> element to the HTML helper.
How can I define <i class="glyphicon glyphicon-arrow-right"></i> inside HTML helper?
Use #Url.Action
<a href="#Url.Action("About", "Home")" class="btn btn-3d btn-xlg btn-reveal btn-brown">
<i class="glyphicon glyphicon-arrow-right"></i>
<span>REVEAL EXTRA LARGE</span>
</a>

use rails button in form as link

I have a table with sliders (part of a form) in one column and a button (link to other page)
<button onclick="location.href='/main';">
<i class="icon icon-078-settings icon--s2" aria-hidden="true"></i>
</button>
Instead of opening the page, the button just submits the form. Any way I can fix this without breaking the table or the form?
Why don't just use anchor tag
<a href='/main'>
<i class="icon icon-078-settings icon--s2" aria-hidden="true"></i>
</a>
or
# If you are using erb
<%= link_to '/main' do %>
<i class="icon icon-078-settings icon--s2" aria-hidden="true"></i>
<% end %>
try below code:
<a href='/main' class="btn btn-primary">
<i class="icon icon-078-settings icon--s2" aria-hidden="true"></i>
</a>
If you used bootstrap css then you can add classes btn and btn-paimary which makes button.
Instead of opening the page, the button just submits the form.
Yes! Buttons are meant to perform actions that effects on front-end or back-end, they are not meant for navigation. You should use links(a.k.a anchors) to perform navigation.
<a href='/main'>
<i class="icon icon-078-settings icon--s2" aria-hidden="true"></i>
</a>

How can I implement variable to <i> tag class in Razor view

I'm trying add an icon with using awesome font.
I used bootstrap button type and it's working fine.But when i would like to add a social icon using tag it does not seem.How can i do that ?
<div id="socialLoginList">
<p>
#foreach (AuthenticationDescription p in loginProviders)
{
<button type="submit" class="btn btn-lg btn-social btn-#p.AuthenticationType.ToLower()" id="btn-socialID" name="provider" value="#p.AuthenticationType" title="Log in using your #p.Caption account"><i class="fa fa-#p.AuthenticationType"></i>#p.AuthenticationType</button><br /><br />
}
</p>
</div>
Simply do a ToLower here:
<i class="fa fa-#p.AuthenticationType.ToLower()">
Font awesome icons are all lower case, so it should pick them up if you do a ToLower. Remember that HTML class names are case-sensitive.
E.g.
<i class="fa fa-google"></i>
<i class="fa fa-facebook"></i>

MVC Razor string.format in html.raw

I use this razor code to generate a HTML button that calls a function with a value from the model:
Html.Raw(string.Format("<button type='button' class='btn btn-success btn-xs' onclick='setCoordinatorForService('{0}')'>Åta</button>", item.Name))
The value of item.Name is "abc", the code:
<button type="button" class="btn btn-success btn-xs" onclick="setCoordinatorForService(" abc')'="">Åta</button>
I want this:
<button type="button" class="btn btn-success btn-xs" onclick="setCoordinatorForService("abc")'="">Åta</button>
What am i doing wrong?
You must replace ' to \"
If you use this code, probably it works very well.
Html.Raw(string.Format("<button type=\"button\" class=\"btn btn-success btn-xs\" onclick=\"setCoordinatorForService('{0}')\">Åta</button>", item.Name)))
Besides the line you wanted it has error.
onclick="setCoordinatorForService("abc")'=""
part maybe give an error because of =

Resources