Asp.net mvc 如何使用ASP.NET MVC在CMS中创建页面?

Asp.net mvc 如何使用ASP.NET MVC在CMS中创建页面?,asp.net-mvc,model-view-controller,Asp.net Mvc,Model View Controller,在内容管理系统中,您通常可以动态创建页面,例如 www.website.com.au/home.aspx www.website.com.au/projects.aspx www.website.com.au/contact-us.aspx 在我们之前编写的CMS中,当用户选择在其站点中创建新页面时,我们在磁盘上实际创建了这些文件。我们从基本模板页面复制了新文件,重命名了文件,并在代码隐藏中重命名了类 template_page.aspx和template_page.aspx.cs变成 proj

在内容管理系统中,您通常可以动态创建页面,例如

www.website.com.au/home.aspx

www.website.com.au/projects.aspx

www.website.com.au/contact-us.aspx

在我们之前编写的CMS中,当用户选择在其站点中创建新页面时,我们在磁盘上实际创建了这些文件。我们从基本模板页面复制了新文件,重命名了文件,并在代码隐藏中重命名了类

template_page.aspx和template_page.aspx.cs变成

projects.aspx和projects.aspx.cs

这一切都是通过我们的CMS应用程序完成的。无需用户手动创建任何文件

使用MVC这种方法如何工作

例如www.website.com.au/home/

www.website.com.au/projects/

www.website.com.au/contact-us/

大概我们需要动态地创建控制器和视图

这似乎比旧方法更混乱,但我认为它是可行的


有人能想出更聪明的方法吗?

你应该能够使用一个控制器和几个视图(显示、创建、编辑)来完成一些布线工作。我为一个像这样的个人项目做了一个超级简单的实现。我将此路由放在路由列表的顶部附近,并使用约束确定是否应将其视为规则中的静态页面。我的实现没有任何层次结构,即页面/关于我们/仅联系人/联系人

route:
routes.MapRoute("StaticContent", "{title}",
  new { controller = "Page", action = "Details"},
  new { title = new InvalidTitleContstraint()});


controller:
public class PageController : Controller
{
    // Details checks if it can find a matching title in the DB
    // redirects to Create if no match 
    public ActionResult Details(string title)
    // GET
    public ActionResult Create()
    // POST
    public ActionResult Create(Page page)
}

您应该能够使用一个控制器和几个视图(显示、创建、编辑)进行一些布线工作。我为一个像这样的个人项目做了一个超级简单的实现。我将此路由放在路由列表的顶部附近,并使用约束确定是否应将其视为规则中的静态页面。我的实现没有任何层次结构,即页面/关于我们/仅联系人/联系人

route:
routes.MapRoute("StaticContent", "{title}",
  new { controller = "Page", action = "Details"},
  new { title = new InvalidTitleContstraint()});


controller:
public class PageController : Controller
{
    // Details checks if it can find a matching title in the DB
    // redirects to Create if no match 
    public ActionResult Details(string title)
    // GET
    public ActionResult Create()
    // POST
    public ActionResult Create(Page page)
}