1

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 }             
);
tereško
  • 58,060
  • 25
  • 98
  • 150
Sunny Sharma
  • 4,688
  • 5
  • 35
  • 73
  • It should work, only when we supply values for properties that do not correspond with segment variables, the values are appended to the outgoing URL as the query string. So i guess something is wrong with the routes. If it's working with Anuraj's example, then you misspelled the property name. – Flavia Obreja Sep 05 '13 at 12:36
  • @FlaviaObreja : it's not working with anuraj's example, any more suggestion? – Sunny Sharma Sep 06 '13 at 04:56

2 Answers2

2

Did you tried like this?

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

Source : HTML.ActionLink method

Community
  • 1
  • 1
Anuraj
  • 18,859
  • 7
  • 53
  • 79
  • thanks for your reply but it didn't work, returns link like: **"/HOD/Attendance?Key=xyz%2Fabc"** – Sunny Sharma Sep 06 '13 at 04:54
  • 1
    I tried the following - @Html.ActionLink("Hello World", "ShowDetails", new { id = "1" }, null) and it is returning something like - http://localhost:50446/Home/ShowDetails/1 and this is my route config - routes.MapRoute( name: "Default", url: "{controller}/{action}/{id}", defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } ); – Anuraj Sep 06 '13 at 05:02
  • thanks a lot, I was not putting my attention towards my routeMap comfig. I had two routeMaps added with same parameters. Thanks for sharing the routeMap config. – Sunny Sharma Sep 06 '13 at 05:35
1

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>
jbl
  • 15,179
  • 3
  • 34
  • 101
  • thanks for your reply... tried it but didn't work. Gives me the link like: **"/HOD/Attendance?empid=xyz%252fabc"** – Sunny Sharma Sep 06 '13 at 04:52
  • @Sunny thx for the follow-up. For what it is worth, another option is to define your route url as "{controller}/{action}/{*empid}" the star would then grasp the / – jbl Sep 06 '13 at 09:06