2011-04-16 122 views
2

我正在研究ASP.NET(MVC3 HTML5)网站。我需要以某种方式允许管理员编辑新闻,主页文本,促销等内容。我可以使用现有的API来实现这一点吗?ASP.NET动态内容

谢谢。

+0

管理员需要在网站的前端执行此操作吗?或通过内容管理系统? – Rob 2011-04-16 11:40:15

+0

它是前端编辑。 – 2011-04-17 05:09:31

回答

1

很简单。 将界面编辑您想要的管理编辑,并与[授权]保护它的属性

//for the users  
    [Authorize] 
    public ActionResult NormalUsers(int newsItemId) 
    { 
     //Getting content from DB. 
     NewsItem news = new NewsItem(newsItemId); 
     return View("ShowNews", news); 
    } 

    //for editors 
    [Authorize(Roles = "Admin, Super User")] 
    [HttpGet] 
    public ActionResult AdministratorsOnly(int newsItemId) 
    { 
     //Getting content from DB 
     NewsItem news = new NewsItem(newsItemId); 
     return View("EditNews", news); 
    } 

    [Authorize(Roles = "Admin, Super User")] 
    [HttpPost] 
    public ActionResult AdministratorsOnly(NewsItem newsItem) 
    { 
     //Putting content in DB 
     newsRepository.StoreNewsItemInDB(newsItem); 
     NewsItem news = new NewsItem(newsItem.Id);//getting the newsItem from DB, to allow for server side processing. 
     return View("EditNews", news); 
    } 

Link to MSDN for the language details.

它可以工作方式的内容是,你有两个(实际上有三个)的意见为新闻。 第一个视图用于为普通用户呈现NewsItem对象。

第二个视图用于获取NewsItem对象进行编辑。 第三个视图用于显示编辑后的NewsItem对象,以确保编辑的最终结果。

用户总是会看到上次编辑的NewsItem(与3相同)。

+0

是的,这是正确的,但我怎样才能指定管理员正在编辑该页面,这将显示给用户? – 2011-04-16 13:02:13

+0

这是两个不同的页面,其中一个是只读的用户,另一个编辑相同的内容(数据库,客户关系管理,XML或任何你喜欢保存内容)。 您的用户将永远不会进入管理员视图,因此无法编辑。 另一个优点是你可以以不同的方式对它们进行设计。漂亮的用户和商务 - 就像管理员(他们喜欢这个:-))。 – Guidhouse 2011-04-16 18:19:35

+0

但是如果将来我需要一些其他内容才是动态的呢?有没有办法直接编辑管理员的用户视图? – 2011-04-16 19:33:01