【发布时间】:2011-03-21 19:44:13
【问题描述】:
我目前正在使用jQuery portlets/sortable/draggable 开发一个门户,该门户还包括一个内容管理系统,全部在ASP.NET MVC 2. 目前只有管理员能够更改站点的布局/内容。
每个视图都基于 Controller 和 Action 获得页面的个性化(来自基本控制器)。然后视图循环遍历小部件并为每个小部件调用 renderaction。
目前,我在每个视图上都有查看 +“编辑”操作,以将页面设置为编辑模式。因为我在复制代码,所以肯定有更好的方法,但我一辈子都看不到它!
您将如何实现允许编辑每个视图的操作?
public ActionResult Legal()
{
PageModel model = GetPageSetting();
return View("Portal", model.PageSetting.Master.Path, model);
}
[HttpPost]
[Authorize(Roles = "Administrator")]
public ActionResult LegalEdit(EditorModel e)
{
PageModel model = GetPageSetting("Legal", "Home", true);
return View("Portal", model.PageSetting.Master.Path, model);
}
//这是在基本控制器中
protected PageModel GetPageSetting(string action, string controller, bool isEditing)
{
PersonalizationProcess personalizationProcess = new PersonalizationProcess();
string path = string.Format("~/{0}/{1}", controller, action);
string userName;
bool isAuthenticated;
if (User == null)
{
userName = "TestUser";
isAuthenticated = false;
}
else
{
userName = User.Identity.Name;
isAuthenticated = User.Identity.IsAuthenticated;
}
PageSetting setting = personalizationProcess.GetPageSetting(userName, isAuthenticated, path);
PageModel model = new PageModel();
model.Act = action;
model.Con = controller;
model.IsEditing = isEditing;
model.PageSetting = setting;
return model;
【问题讨论】:
标签: jquery asp.net-mvc-2 content-management-system portal