Click here to Skip to main content
15,884,739 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear All,
When I add a css class to my ActionLink HTML helper in my application it doesn't navigate to the specified url but When I remove the css class it works perfect how can have a CSS class to go along with HTML.ActionLink?

Following is my code:
1) When I write the below code it works perfect.
HTML
@Html.ActionLink("ICD9s", "Index", "EHR")

2) When I write the below code it doesn't navigate to the specified url.
HTML
@Html.ActionLink("ICD9s", "Index", "EHR", new { @class = "linkbtnfull"})


Thanks
Posted
Updated 2-May-18 22:29pm
v2

Try this.....

@Html.ActionLink("Link Name",
"ActionName",
"ControllerName",
null,
new { @class = "linkbtnfull" }
)


you code should be,

@Html.ActionLink("ICD9s", "Index", "EHR", null,new { @class="linkbtnfull"})
 
Share this answer
 
v3
Specify which type of error occurs or what happens when you click the link.
I have below format for writing action link which is working :

C#
@Html.ActionLink("ICD9s", "Index", "EHR", null,new { @class="round"})

@Html.ActionLink("ICD9s", "Index", new { Controller = "EHR" },new { @class="round"})
 
Share this answer
 
Comments
Nischal Bhatt 10-Jul-14 1:01am    
Hey! Arvind,
@Html.ActionLink("ICD9s", "Index", "EHR", null,new { @class="round"}) did the trick man.
Thanks.
arvind mepani 10-Jul-14 1:08am    
Your most welcome friend :)
Hi,

Try to use _class="linkbtnfull" instead of @class = "linkbtnfull"

you code should be,

@Html.ActionLink("ICD9s", "Index", "EHR", new { _class = "linkbtnfull"})

hope this works for you........
 
Share this answer
 
Comments
Nischal Bhatt 8-Jul-14 8:12am    
Hi! Hrushikesh
I tried using "_class" but it has the same end result :(
jo.him1988 8-Jul-14 8:19am    
what is inside your linkbtnfull class ??
Nischal Bhatt 8-Jul-14 8:25am    
Following is my "linkbtnfull" css class
.linkbtnfull {
background: url("../images/green-btn.png") repeat-x scroll center top rgba(0, 0, 0, 0);
border: medium none;
border-radius: 3px;
color: #ffffff;
display: inline-block;
font-family: 'open_sansregular';
line-height: 33px;
text-align: center;
width: 100%;
}
jo.him1988 8-Jul-14 8:41am    
i dont know whats going on your ActionLink when i wrote on my code its working fine
@Html.ActionLink("back to search", "Index", "Country", new { @class = "linkbtnfull" })
[no name] 9-Jul-14 1:23am    
I tried with this code and its working fine,I really don't know why this is not working for you....
Actually there is no method with following 3 parameters
@Html.ActionLink("ICD9s", "Index", "EHR", new { @class = "linkbtnfull"})
try this one
@Html.ActionLink("ICD9s", "Index", "EHR",null, new { @class = "linkbtnfull"})
 
Share this answer
 
Please try this
@Html.ActionLink("Create New", "Create", new { }, new { @class = "btn btn-success" })


You must get a blank new{}.

It is working for me.
 
Share this answer
 
Comments
CHill60 3-May-18 4:49am    
Doesn't really add anything to the previous solutions "blank new{}" is null as already stated
N. Shahadat 3-May-18 4:58am    
Please tell me your Controller & Method Name
Works for me....
http://localhost:50973/Emp_BasicInfo/Create

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900