以外的部分,我按照說明這裏http://orchardproject.net/docs/Creating-a-module-with-a-simple-text-editor.ashx果園CMS渲染管理部分
的一個改變我想要做的是,使管理模塊之外的產品創建工作的模塊上。因此,我創建的HomeController像根文件夾
public class Routes : IRouteProvider
{
public void GetRoutes(ICollection<RouteDescriptor> routes)
{
foreach (var routeDescriptor in GetRoutes())
routes.Add(routeDescriptor);
}
public IEnumerable<RouteDescriptor> GetRoutes()
{
return new[] {
new RouteDescriptor {
Priority = 5,
Route = new Route(
"commerce",
new RouteValueDictionary {
{"area", "SimpleCommerce"},
{"controller", "Home"},
{"action", "Index"}
},
new RouteValueDictionary(),
new RouteValueDictionary {
{"area", "SimpleCommerce"}
},
new MvcRouteHandler())
},
new RouteDescriptor {
Priority = 6,
Route = new Route(
"commerce/Create",
new RouteValueDictionary {
{"area", "SimpleCommerce"},
{"controller", "Home"},
{"action", "Create"}
},
new RouteValueDictionary(),
new RouteValueDictionary {
{"area", "SimpleCommerce"}
},
new MvcRouteHandler())
}
};
}
}
所以我應該如何從這裏開始移動渲染這件事一起,當我瀏覽到網址http://localhost:35713/commerce/create這
public class HomeController : Controller
{
public HomeController(IContentManager cm) {
ContentManager = cm;
}
private IContentManager ContentManager { get; set; }
public ActionResult Index() {
return Content("This is index");
} [Themed]
public ActionResult Create()
{
var product = ContentManager.New("Product");
var model = ContentManager.BuildEditor(product);
return View((object) model);
}
和文件routes.cs
但它會拋出一個錯誤,說創建視圖找不到。然後,我創建了一個視圖視圖(create.cshtml)/ Home文件夾
@model SimpleCommerce.Models.ProductPart
<fieldset>
<label class="sub" for="Sku">@T("Sku")</label><br />
@Html.TextBoxFor(m => m.Sku, new { @class = "text" })<br />
<label class="sub" for="Price">@T("Price")</label><br />
@Html.TextBoxFor(m => m.Price, new { @class = "text" })
</fieldset>
現在,它拋出一個錯誤說
傳遞到字典的模型產品類型「IShapeProxyedcfa08c61cf49898dc2e77bde025039」,但這字典需要一個'SimpleCommerce.Models.ProductPart'類型的模型項目。
那麼如何實現結果呢。 – user311143
使用非Lambda重載。或者將強類型模型傳遞到視圖中,而不是通過buildeditor爲您提供的形狀。 –
您的產品部件位於Model.ContentItem屬性中,只需在您的形狀中創建一個變量,如'@ {var product = Model.ContentItem.As( );}'你也可以自由地使用基於lambda的助手。 –