asp.net - Dynamic pages in MVC4 -
i'm building small mvc4 site, i've run in little problem :/
the site have admin area, , in area administrator of site, should able dynamicly create new pages. let's admin creates new page called "world" under page called "hello". when user navigates the.domain.com/hello/world newly created page should shown. it's basicly functionality of simple cms system.
so, need way redirect calls not covered controller , action, 1 specific action on 1 specific controller.
i've done before in webforms using urlrewriting. checked if aspx page existed on disk, , if didn't redirected page called pagehandler.aspx?pageid={some_page_id}, guess there way routing in mvc4?
you can pass strings view()
, should able catch route this:
routes.maproute( name: "dynamicpageview", url: "page/{pagename}", defaults: new { controller = "page", action = "displaypage", pagename = "index" } );
this hit method this:
[httpget] public actionresult displaypage(string pagename) { return view(viewname: pagename); }
i've done similar myself host mockups; controller method can handle arbitrary number of pages , can extended handle subfolders, it's great throwing dummy pages can navigated real site.
having said that, it's worth saying possible, i'd prefer keep end users (even admins) away internals expose. instead, should come model represents on page, store that, , use template display id or title.
Comments
Post a Comment