Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC my url is creating "?Length=4"

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 ...

like image 987
user2739679 Avatar asked Sep 11 '13 06:09

user2739679


People also ask

Where is RouteConfig in MVC?

Every MVC application must configure (register) at least one route configured by the MVC framework by default. You can register a route in RouteConfig class, which is in RouteConfig. cs under App_Start folder.

What is URL pattern in MVC?

Typical URL Patterns in MVC Applications URL patterns for routes in MVC Applications typically include {controller} and {action} placeholders. When a request is received, it is routed to the UrlRoutingModule object and then to the MvcHandler HTTP handler.


2 Answers

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

like image 50
Ufuk Hacıoğulları Avatar answered Oct 04 '22 23:10

Ufuk Hacıoğulları


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.

like image 45
devio Avatar answered Oct 05 '22 00:10

devio