没有管理员的Orchard数据输入表单

时间:2014-06-23 18:21:38

标签: asp.net-mvc orchardcms orchardcms-1.8 orchard-modules

我们正在努力学习Orchard,目标是创建非网站,但我们通常会在几个月内使用MVC编写以业务为中心的Web应用程序,但希望通过使用各种部件提高效率已经可以。

最后一英里似乎是个大块 - 如何告诉Orchard它应该创建一个允许最终用户编辑某些数据的形状?在Creating a module for Orchard that stores data from the front-end的大部分最终用户编辑中都有一点点好处,但是在已经输入数据并且通过控制器的POST操作进行数据传输后它会恢复。我无法弄清楚如何完成最初的GET操作。

详细说明,在直接MVC中,我可能允许用户输入关于他们自己的信息。所以我有/Controllers/PersonController.cs,并编写了一个Create()函数。我在/Views/Person/Create.cshtml中添加了一个视图,只需"返回View()"来自控制器。在Create(Person p),一个HTTPGet方法中,我执行繁重的工作来保存对象。

现在在Orchard我有我的PersonPart及其PersonPartDriver,正如我从上面的文章中所理解的那样,我会编写我的POST方法来接受PersonPart并保存对象。

class PersonController : Controller
{
   private readonly IRepository<PersonPartRecord> personRepository;

   public PersonController(IRepository<PersonPartRecord> _personRepository) {
      personRepository = _personRepository;
   }

   [HttpPost]
   public Create(PersonPart part) {
      personRepository.Create(part.Record);
   }
}

一切顺利,但是我如何让Orchard调用GET编辑器(PersonPart,动态)方法来获取用户进行初始数据输入的表单?

protected override DriverResult Editor(PersonPart part, dynamic shapeHelper)
{
    return ContentShape("Parts_Person_Edit",
                        () => shapeHelper.EditorTemplate(
                                          TemplateName: "Parts/Person",
                                          Model: part,
                                          Prefix: Prefix));
}

或者我在控制器中编写GET Create()方法?但是,如果我这样做,我绕过整个形状创建系统,不是吗?在我的大脑后面有一些东西说我宁愿做一个Display(),在模板中,只是让它成为一个可编辑的形式,但我有一个Display()用于Person的只读视图......如何制作它知道我想要可编辑的视图吗?

希望这个问题有道理,并希望有人可以提供帮助。

感谢。

1 个答案:

答案 0 :(得分:0)

查看Orchard.CustomForms

var model = _contentManager.BuildEditor(contentItem);
 return View(model);

但你需要像上面代码那样的东西。您也可以返回ShapeResult(this,model)

相关问题