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 urlhttp://localhost:2355/Home/Contract?Length=4
I want my url ashttp://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 ...
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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With