How to use MapRoute, using ActionLink()?

I have this route values inside Global.asax

routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults );

        routes.MapRoute(
            "Edit", // Route name
            "Admin/{controller}/{action}/{id}", // URL with parameters
            new { controller = "Edit", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

and I use this ActionLink method to call the Edit route

@Html.ActionLink("Edit", "Topic", "Edit", new { id = item.ID })

Now the result of the link generated is like this...

http://localhost:777/Admin/Topic?Length=4

How to use the route and target properly using ActionLink method.

Thanks!


Use the correct overload of ActionLink to get the intended result

@Html.ActionLink("Edit", "Topic", "Edit", new { id = item.ID }, null)

The overload is ActionLink(string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes)

Adding the null as null HTML attributes is necessary when you supply parameters to the action. Or if you actually needed to apply HTML Attributes to the link, you would use:

@Html.ActionLink("Edit", "Topic", "Edit", new { id = item.ID }, new { @class = "MyCustomCssClassName" } )
链接地址: http://www.djcxy.com/p/49988.html

上一篇: 在使用Ajax.ActionLink()在IIS中进行部署后,Action方法未被触发

下一篇: 如何使用MapRoute,使用ActionLink()?