2014-02-23 37 views
1

我發現的所有文檔都很多,展示瞭如何創建內容類型,使用Umbraco UI捕獲該內容類型的文檔,以及如何創建用於顯示該文檔的模板。如何創建Razor視圖以捕獲Umbraco中的某種內容類型?

我確定我需要一個POST操作,它會得到一個反映內容類型結構的視圖模型;它是變量和其他內容,但是在哪裏可以找到它以及如何處理這些數據對我來說仍然是一個謎。

如何創建文檔捕獲視圖以及如此常見的顯示視圖?

+0

您是否在問如何創建一個將用於創建內容類型的新實例的窗體? – elolos

+0

是的,我在問。我所能找到的所有東西都是關於如何構建用於顯示的模板,可能是捕獲字段,而不是如何實際創建實例。 – ProfK

回答

1

創建表單發佈到表面控制器相當容易。在我們的Umbraco社區網站有一個非常好的教程,可能對您有用。你可以找到教程here

在處理POST的控制器操作中,您需要添加對Umbraco Management API的調用,該調用用於CRUD操作。

下面是如何創建並填充一把umbraco內容文件的屬性的示例6+:

private void AddProduct(int productId, string name, int productGroupId, int price) 
    { 
     // Get the Umbraco Content Service 
     var contentService = Services.ContentService; 

     var product = contentService.CreateContent(
      name,   // the name of the product document 
      productGroupId, // the parent id should be the id of the group node 
      "product",  // the alias of the product Document Type 
      0); 

     // Here's how to update some of the properties 
     product.SetValue("productId", productId); 
     product.SetValue("originalName", name); 
     product.SetValue("priceDKK", price); 

     // finally we need to save and publish, this saves the product and the property values 
     contentService.SaveAndPublish(product); 
} 

有對媒體文件類似的服務,數據類型等詳細信息,看看對於早期版本,Umbraco v6 +和herehere

+0

我看不出如何在該教程中實際保留文檔的示例。它只是返回一個成功消息,但表單如何到達數據庫?這就是我的文檔不足。 – ProfK

+0

好的,現在我得到你想要找的東西。我會相應地更新我的答案。 – elolos

+0

'name','parentId'等描述內容類型?實例數據,例如'bodyText'會自動提取? – ProfK

相關問題