mvc.net路由:routevalues在maproutes [英] mvc.net routing: routevalues in maproutes
本文介绍了mvc.net路由:routevalues在maproutes的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要像/控制器/动词/名词/ ID的URL和我的操作方法是动词+名词。例如我想的/ home /编辑/团队/ 3击中操作方法
i need urls like /controller/verb/noun/id and my action methods would be verb+noun. for example i want /home/edit/team/3 to hit the action method
public ActionResult editteam(int id){}
我在Global.asax文件下列路线。
i have following route in my global.asax file.
routes.MapRoute(
"test",
"{controller}.mvc/{verb}/{noun}/{id}",
new { docid = "", action = "{verb}"+"{noun}", id = "" }
);
网址正确匹配路线,但我不知道我应该构建操作参数是操作方法的名字被调用。
问候
urls correctly match the route but i don't know where should i construct the action parameter that is name of action method being called.
regards
推荐答案
的尝试:的
public class VerbNounRouteHandler : IRouteHandler
{
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
IRouteHandler handler = new MvcRouteHandler();
var vals = requestContext.RouteData.Values;
vals["action"] = (string)vals["verb"] + vals["noun"];
return handler.GetHttpHandler(requestContext);
}
}
我不知道的方式把它挂自动所有路由,但在你的情况下,你可以像入门做到这一点:
I don't know of a way to hook it for all routes automatically, but in your case you can do it for that entry like:
routes.MapRoute(
"test",
"{controller}.mvc/{verb}/{noun}/{id}",
new { docid = "", id = "" }
).RouteHandler = new VerbNounRouteHandler();
这篇关于mvc.net路由:routevalues在maproutes的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文