html entity in ActionLink - razor

How can I include html entities in ActionLink. e.g. The case of » below.
<p>#Html.ActionLink("Link Text »", "Index", new { }, new { #class = "btn btn-warning", #role = "button" })</p>

Use Url.Action instead
<p><span class="btn btn-warning">Link Text »</span></p>

Related

MVC Placeholder in Dropdownlist

How can I put a placeholder in a dropdownlist? I already had to search, but I still could not find the solution.
HTML
<div class="wrap-input100 rs1-wrap-input100 validate-input">
<span class="label-input100">Room</span>
#Html.DropDownList("ID_Room", null, htmlAttributes: new { #class = "focus-input100" })
<span class="focus-input100"></span>
</div>
#Html.DropDownList("ID_Room", null, "placeholder" , new { #class = "focus-input100" })
Also. you don't need to htmlAttributes. Just having new {} is fine

How to incorporate href to section with Html.ActionLink in MVC?

I am new to MVC and have encountered a problem. I have an HTML page that scrolls down to a section when that section's name is clicked from the navigation bar but now I have to change this HTML line of code to MVC:
<li><a class="page-scroll" href="#services">Services</a></li>
I have tried to use Html.ActionLink but have not had any success yet!
What I have so far:
#Html.ActionLink("Services", "Index", "Home", new { area = "#services" }, new { #class = "page-scroll" })
Create your own helper or use raw html
<li>Link Text</li>
OR
<%= Html.ActionLink("Link Text", "Action", "Controller", null, null, "services", new { parameter = "example"}, null) %>
On your Index page:
<div id="services">
<p>Here is the content you want to make show when you click the link</p>
</div>
When you click on 'Link Text' it will direct you to the services section of your Index page.
Try
#Html.ActionLink("Services", "Index", "Home#services", new { #class = "page-scroll" })

How can I add a caret to text passed to #Html.ActionLink in MVC5

I want to display
Username v
as the text displayed for the link.
I wanted to use <class = "caret"> but I can't pass it successfully and the HTML code is being printed next to Username.
In most cases the Html.ActionLink will do the trick, if you want more control over the href tag you can use #Url.Action.
Examples:
#Html.ActionLink(Model.Username, "Username", "Account", new { #class = "caret" })
HTML Result: <a class="caret" href="/Account/Username">SomeUsername</a>
<a class="caret" href="#Url.Action("Username", "Account")">#Model.Username</a>
HTML Result: <a class="caret" href="/Account/Username">SomeUsername</a>

How to apply CSS class to HTML Action Link in Razor

I have got:
<p><a class="btn btn-default" href="~/Person">List of Cients »</a></p>
I would like to replace it with HTML Action Link but don't change visual style.
I want to get to Index Action of PersonController:
public class PersonController : Controller
{
private PersonContext db = new PersonContext();
// GET: Person
public ActionResult Index()
{
return View(db.Persons.ToList());
}
}
How the #Html.ActionLink(...) should look like.
EDIT:
I tried:
<p><a class="btn btn-default" href="~/Person">List of Cients »</a></p>
#Html.ActionLink("List of Clients &raquo", "Index", "Person", new { #class = "btn btn-default" })
There is the problem with: » ActionLink does not renders preetty arrow.
EDIT2:
Tried this with no result: #Html.ActionLink("List of Clients " + HttpUtility.HtmlDecode("&raquo"), "Index", "Person", new { #class = "btn btn-default" })
EDIT:
Both don't work.
<p> #Html.ActionLink("List of Clients »", "Index", "Person", new { #class = "btn btn-default" })</p>
<p> #(Html.ActionLink("List of Clients »", "PersonController/Index", new { #class = "btn btn-default" }));
First gives right style but when I click I get length=6 in the link.
Second does not have style and links to: http://localhost:17697/Home/PersonController/Index?class=btn%20btn-default
ANSWER: This one works:
<p> #Html.ActionLink("List of Clients »", "Index", "Person", null, new { #class = "btn btn-default" })</p>
#(Html.ActionLink("Title", "/PersonController/Index", new { #class = "myCssClass" }));
Here's a link for reference: http://msdn.microsoft.com/en-us/library/dd492124(v=vs.108).aspx
Please try this, it will work
<a href="#Url.Action("Index", "Person")">
<button class="btn btn-default">
List of Cients »
</button>
</a>
try this
#Html.ActionLink("ButtonText", "Action","Controller", new {#class="btn btn-default"})
it's what worked for me.
NB. the new {#class="btn btn-default"} goes after the 3rd comma.
<pre>
<p>I will display »</p>
<div>
#Ajax.ActionLink("Contact " + HttpUtility.HtmlDecode("»"),
"_PartialEmployeeIndex", "Employee",
new AjaxOptions() { UpdateTargetId = "divToUpdate" },
new { #class = "btn btn-primary" })
</div>
</pre>

Displaying multiple #Html.ActionLink in same line

How can I display 2 Html Action Links in a same line, that are using different action from a different controller? My code is:
<th>#Html.ActionLink((item.Name + " & "), "Index", "Wedding") #Html.ActionLink("Invite Partner", "InvitePartner", "Account")</th>
With this both actions are displayed in a different paragraph. How can I display them in a same paragraph?
EDIT:
It is all about the style, I've added bootstrap classes, and it is showing as buttons in same paragraph:
<th>#Html.ActionLink((item.Name + " & "), "Index", "Wedding", new { #class = "btn btn-default"}) #Html.ActionLink("Invite Partner", "InvitePartner", "Account", new { #class = "btn btn-danger"})</th>