【问题标题】:How would you use ASP.NET MVC to create pages in a CMS?您将如何使用 ASP.NET MVC 在 CMS 中创建页面?
【发布时间】:2009-04-28 04:12:31
【问题描述】:

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

www.website.com.au/home.aspx

www.website.com.au/projects.aspx

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

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

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/

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

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

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

【问题讨论】:

    标签: asp.net-mvc model-view-controller


    【解决方案1】:

    您应该能够使用一个控制器和几个视图(显示、创建、编辑)进行一些路由工作。我为一个像这样的个人项目做了一个超级简单的实现。我把这条路由放在我的路由列表顶部附近,并使用约束来确定它是否应该被视为我的规则中的静态页面。我的实现没有任何层次结构,即 pages/About-us/contact - 只有 /contact。

    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)
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-23
      • 2017-09-04
      • 2015-09-30
      • 1970-01-01
      • 2016-08-12
      • 1970-01-01
      • 2010-10-13
      • 2011-03-31
      相关资源
      最近更新 更多