Sunny Sharma
Sunny Sharma

Reputation: 4934

ActionLink not working as expected

I'm passing empid and I want it to be shown in url but it shows like querystring:

<li>@Html.ActionLink(key.Value, "Attendance","HOD",  new {empid=key.Key}, null) 
                                                                           </li>

The link I want to display is like:

 /HOD/Attendance/xyz%2Fabc

but it shows me like this:

/HOD/Attendance?empid=xyz%2Fabc //it's like query string but i don't want that.

Can somebody please help? I appreciate any little help. Thanks a lot in advance.

I've this RouteMap added to Global.asax

routes.MapRoute (
     "HOD_AttByEmpID", // Route name
     "{controller}/{action}/{empid}", // URL with parameters
     new { controller = "Account", action = "LogOn", 
                                    empid = UrlParameter.Optional }             
);

Upvotes: 1

Views: 158

Answers (2)

jbl
jbl

Reputation: 15413

I guess that is because your value contains a '/'

Maybe you can try :

<li>@Html.ActionLink(key.Value, "Attendance","HOD",
         new {empid=Server.UrlEncode(key.Key)}, null) 
</li>

Upvotes: 1

Anuraj
Anuraj

Reputation: 19598

Did you tried like this?

@Html.ActionLink(key.Value, "Attendance","HOD",  new { key.Key},null)

Source : HTML.ActionLink method

Upvotes: 2

Related Questions