是否可以将参数从"url“部分传递到MapRoute的”默认“部分中的方法?
routes.MapRoute(
name: "Language",
url: "{language}/{controller}/{action}/{id}-{description}",
defaults: new { Controller = "Home", action = "Index", id = UrlParameter.Optional, language = UrlParameter.Optional, description = GetDescription(id) }
);我可以在没有任何参数的情况下调用GetDescription(),但是我不知道如何从url ie传递一个参数。GetDescription(id)?
发布于 2014-11-26 08:30:28
我认为你误解了路线定义的概念。不能将动态行为添加到死记硬背注册过程中,因为它只在应用程序启动事件上执行一次。当路由引擎在提供的URL中找不到合适的参数时,将使用默认参数。在url生成级别上,您想做什么是可能的:
@Html.ActionLink("Home", "Index", new { language = "en", id=5, description = "test" })https://stackoverflow.com/questions/27138101
复制相似问题