Orchard CMS中有一个模块,允许在仪表板中编辑模板,但不清楚如何正确利用输出。在MVC模块控制器中访问模板,将模板传递给模型,然后在View cshtml文件中呈现它,正确的方法是什么?
发布于 2015-09-10 15:05:06
您可以使用shapefactory构建任何形状:
public MyController(IShapeFactory shapeFactory) {
Shape = shapeFactory;
}
public dynamic Shape { get; set; }
public ActionResult Index() {
var someModel = new SomeModel();
// You can build your shape here:
var shape = Shape.TheTemplateShapeName(SomeData: someModel.SomeProperty);
// or: Shape.New("TheTemplateShapeName").SomeData(someData);
// you can just chain on the dynamic shape
var viewModel = Shape
.ViewModel() // simple orchard method to build a viewmodel with chaining
.MyShape(shape)
.SomethingElse("Some string");
return View(viewModel);
}然后在您的MyController/Index.cshtml中:
<h1>@Model.SomethingElse</h1>
@Display(Model.MyShape)https://stackoverflow.com/questions/32490573
复制相似问题