ASP.NET MVC路由的单控制器网站 [英] ASP.NET MVC Routing for a Single Controller Site

查看:72
本文介绍了ASP.NET MVC路由的单控制器网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个简单的网站。基本上,它有一个控制器首页控制器。

I'm trying to create a simple site. Basically it has one Controller Home controller.

该控制器具有一个动作首页需要字符串作为参数(这是一个目录),并使用了目录来完成工作。

This controller has an action Index takes a string as argument (which is a directory) and uses that 'directory' to do its work.

我不知道如何创建一个通用的追赶,将每个URL发送到这个行动的所有航线。

I can't work out how to create a generic catch all route that will send every URL to this one Action.

任何URL组合可以存在的,任何超出该域名应该是字符串。

Any URL combination could exist, and anything beyond the domain name should be the string.

的http://&LT结构域GT; / 2008

的http://&LT结构域GT; / 2008/09

的http://&LT结构域GT; / 2008/09 /弗雷德

有谁知道如何做到这一点?这也将是正常的,如果所有的值都为列表过去了。

Does anyone know how to do this? It would also be alright if all the values are passed as a list.

是否有这样做的更好的办法?

Is there a better way of doing this?

推荐答案

试试这个:

routes.MapRoute(
        "Default", "{*path}",
        new { controller = "Home", action = "Index" } 
    );

和控制器:

public class HomeController : Controller {
    public ActionResult Index(string path) {
        return View();
    }
}

这篇关于ASP.NET MVC路由的单控制器网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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