匹配URL参数跨越多个" /"在ASP.NET MVC [英] matching URL parameter spanning multiple "/" in ASP.NET MVC

查看:100
本文介绍了匹配URL参数跨越多个" /"在ASP.NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是匹配URL参数跨越多个的最佳途径/,在ASP.NET MVC?

What is the best way to match URL parameter spanning multiple "/" in ASP.NET MVC ?

例如网址: http://example.com/controller/action/p1 / P2 / P3 / P4

我想只有一个参数传递给操作方法(上面,它是P1 / P2 / P3 / P4)。这里,参数可以具有子项的任意数量(P1 /.../ PN)。

I want to pass just one parameter to the action method (above, it is "p1/p2/p3/p4"). Here, the parameter may have arbitrary number of subitems ( p1/.../pn ).

什么是实现这一目标的最佳途径?没有办法让这个使用纯MVC路由实现的?

What is the best way to accomplish this? Any way to get this implemented using pure MVC routing?

推荐答案

如果我了解清楚你想这样说。

If i understand it clearly you want to make it this way

routes.MapRoute(null, "{controller}/{action}/{*p}", new { controller = "Home", action = "Index" });

public class HomeController : Controller
{
    public ActionResult Index(string p)
    {
        string[] parameters = p.Split('/');
        //Whatever
    }
}

或者你可以用正则表达式做到这一点,你可以看看这个的链接

Or you can do it with regex, you may take a look this link

这篇关于匹配URL参数跨越多个" /"在ASP.NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆