8

I am creating an MVC4 application. I have a small issue. My code is

<li id="tabHeader_2">@Html.ActionLink("Contract", "Contract", "Home", new { id = "lnk_contract" })</li>

I am getting url
http://localhost:2355/Home/Contract?Length=4

I want my url as
http://localhost:2355/Home/Contract

my ruoting is

routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

If you have answer please help me ...

Karl-Johan Sjögren
  • 16,544
  • 7
  • 59
  • 68
user2739679
  • 827
  • 4
  • 14
  • 24
  • See this thread.. Its actually to do with the html action link http://stackoverflow.com/questions/824279/why-does-html-actionlink-render-length-4 – Nico Sep 11 '13 at 06:57

2 Answers2

13

You mixed up the parameters. You have to send anonymous object as htmlAttributes parameter.

@Html.ActionLink("Contract", "Contract", "Home", null ,new { id = "lnk_contract" })

Here's the MSDN page for this overload:

http://msdn.microsoft.com/en-us/library/dd504972(v=vs.108).aspx

Ufuk Hacıoğulları
  • 37,978
  • 12
  • 114
  • 156
1

You need to add the parameter

, new {}

to Html.ActionLink.

The first object is for the query string, the second is for the HTML parameters.

devio
  • 36,858
  • 7
  • 80
  • 143