#Html.ActionLink not working for css class - asp.net-mvc

Action link #class="info" not working for css
#Html.ActionLink("Click Here", "Details", "Product", new { id = item.ProductId, #class="info" },null)
Html page source
Click Here
Update:
on the other hand
if i set #Html.ActionLink("link here", "Details", "Product", new { id = item.ProductId}) then generate this link localhost:18715/Home/Details?Length=7 why? and it is not working
if i set #Html.ActionLink("link here", "Details", "Product", new { id = item.ProductId},null)
it is working perfectly generate this link http://localhost:18715/Product/Details/17
what i am missing for each link

You have to write hmtl attributes like this:
#Html.ActionLink("Click Here", "Details", "Product", new { id = item.ProductId }, new { #class = "info"})

#Html.ActionLink("Back", "Index", " ", new { #class = "col-sm-3 btn btn-outline-secondary btnfs btn-sm" })
Here more than one CSS calls is attached to the for ActionLink. This is For
Asp.net MVC

Related

where to add new {target = "_blank"} in the link #Html.ActionLink ASP.NET MVC

I need to open the link in new page when click the link but where to add the code
new {target = "_blank"}
in this link ,
<td>#Html.ActionLink("Result", "MasterDetails", new { id = item.LabOrders.ORDER_ID }, new { #class = "btn btn-primary" })</td>
It's part of the htmlArguments, after the route value. You don't necessarily put the whole thing in; you merge with other html arguments, such as #class:
<td>
#Html.ActionLink("Result", "MasterDetails",
new { id = item.LabOrders.ORDER_ID},
new { #class = "btn btn-primary", target="_blank" })
</td>

How can I use the Bootstrap Badge class within MVC Razor?

How can I use the Bootstrap Badge class to show a number next to the button? In this case I am using the #ActionLink. I've seen on the bootstrap page that I'm supposed to use a HTML span for the Badge.
Code:
<div class="row">
<div class="col-md-2">
<div class="list-group">
#Html.ActionLink("Home", "Index", "Home", null, new { #class = "list-group-item" })
#Html.ActionLink("Auto's", "Lijst", "Auto", null, new { #class = "list-group-item" })
#Html.ActionLink("Medewerkers", "Lijst", "Medewerker", null, new { #class = "list-group-item" })
<!--This one!--> #Html.ActionLink("Dagprogramma", "Dagprogramma", "Medewerker", null, new { #class = "list-group-item"} )
#Html.ActionLink("Contact", "Contact", "Home", null, new { #class = "list-group-item" })
</div>
</div>
You cannot include custom html markup inside the link markup generated by ActionLink helper method. What you can do is, write an anchor tag and include the span inside that. Use the Url.Action method to generate the correct relative url to the action method which you will use as the link's href attribute value.
#Html.ActionLink("Medewerkers", "Lijst", "Medewerker", null,
new { #class = "list-group-item" })
<a href="#Url.Action("Dagprogramma","Medewerker")"
class="list-group-item"> Dagprogramma <span class="badge">99</span>
</a>
#Html.ActionLink("Contact", "Contact", "Home", null,
new { #class = "list-group-item" })

MVC Pass textbox to controller if not in a form tag

I am working on and Microsoft MVC3 project and cannot pass a parameter which has been edited to the controller. It will only pass back the original set parameter
For example:
#Ajax.ActionLink("share file", InviteController.Actions.Result, InviteController.Name, new { message = Model.Message }, new AjaxOptions
{
HttpMethod = "GET",
UpdateTargetId = "popup",
OnSuccess = "$('#popup').dialog('open')"
}, new { id = "popup-button" })
<label>Personal Message <span class="optional-message">(optional)</span></label>
#Html.TextAreaFor(x => x.Message)
</div>
This will pass the to the following controller but the 'message' parameter has the original message and not the updated message:
public ActionResult Result(FormCollection coll, string message)
{
I'd love if someone could give me some advice.
Many Thanks
Use a form instead:
#using (Ajax.BeginForm(
InviteController.Actions.Result,
InviteController.Name,
null,
new AjaxOptions
{
HttpMethod = "GET",
UpdateTargetId = "popup",
OnSuccess = "$('#popup').dialog('open')"
},
new { id = "popup-button" }))
{
<label for="Message">
Personal Message
<span class="optional-message">(optional)</span>
</label>
#Html.TextAreaFor(x => x.Message)
<button type="sybmit">share file</button>
}
And don't forget that HTML forms cannot be nested. So if you have an outer form this won't work.

How to include CSS Class in ActionLink in MVC4

My code is
#Html.ActionLink("test1", "Index", new { Area = "area1", Controller = "controller1" })
I want to include the following css class in the action link.
class="rtsLink"
Also, can we add multiple css class. If so, I need to add another css class.
class="rtsTxt"
Update:
<li class="rtsLI" id="Summary"><span class="rtsTxt">Test</span></li>
Above I am replacing with following actionlink:
<li class="rtsLI" >#Html.ActionLink("test1", "Index", new { Area = "Tools", Controller = "controller1" }, new { #class = "rtsLink rtsTxt"})</li> "
At first css is working fine. But when using Actionlink, css not working. Thanks
You can simply add a new anonymous object as the fourth parameter
#Html.ActionLink("User Security", "Index", new { Area = "Tools", Controller = "UserSecurity" }, new { #class = "rtsLink rtsTxt" })
Note that the word class is reserved in C#, so you must prefix it with an #.
Since you have a span inside anchor. You could try this.
<li class="rtsLI" id="Summary">
<a href="#Url.Action("Index", new { Area = "Tools", Controller = "UserSecurity" })"
class="rtsLink">
<span class="rtsTxt">User Security</span>
</a>
</li>

ActionLink htmlAttributes

WORKS
<a href="#Url.Action("edit", "markets", new { id = 1 })"
data-rel="dialog" data-transition="pop" data-icon="gear" class="ui-btn-right">Edit</a>
DOES NOT WORK - WHY?
#Html.ActionLink("Edit", "edit", "markets", new { id = 1 }, new {#class="ui-btn-right", data-icon="gear"})
It seems you can't pass something like data-icon="gear" into htmlAttributes?
Suggestions?
The problem is that your anonymous object property data-icon has an invalid name. C# properties cannot have dashes in their names. There are two ways you can get around that:
Use an underscore instead of dash (MVC will automatically replace the underscore with a dash in the emitted HTML):
#Html.ActionLink("Edit", "edit", "markets",
new { id = 1 },
new {#class="ui-btn-right", data_icon="gear"})
Use the overload that takes in a dictionary:
#Html.ActionLink("Edit", "edit", "markets",
new { id = 1 },
new Dictionary<string, object> { { "class", "ui-btn-right" }, { "data-icon", "gear" } });
Replace the desired hyphen with an underscore; it will automatically be rendered as a hyphen:
#Html.ActionLink("Edit", "edit", "markets",
new { id = 1 },
new {#class="ui-btn-right", data_icon="gear"})
becomes:
<form action="markets/Edit/1" class="ui-btn-right" data-icon="gear" .../>
#Html.ActionLink("Login", "Index", "hahgshg62jjshags",new { },new { rel = "nofollow", style = "color:white" })
#Html.ActionLink("display name", "action", "Contorller"
new { id = 1 },Html Attribute=new {Attribute1="value"})

Resources