2016-11-20 17 views
-1

我有MVC項目包含許多意見, 我希望客戶端,因爲他/她喜歡的編輯內容並保存。什麼是MVC中CMS的最佳實踐?

我怎樣才能使CMS的意見(內容管理系統)?

我已閱讀關於telerik中的RedEditor,但它只適用於html文件, MVC是包含剃鬚刀的cshtml文件,我無法使用RedEditor處理。

我的問題,我有一個客戶建立網站,現在的客戶要求修改的網站,因爲他喜歡,修改內容..Images ..等,以及所有視圖通過剃刀

防爆建:這在頁面的剃刀 maked我要管理客戶端修改標題&後畫面&保存反映它在直播網站

enter image description here

回答

1

爲了做到在MVC一個簡單的內容管理系統,你可能想organiz Ë東西,這樣的頁面模式是內容項的列表,讓您的視圖迭代的內容項目,並將其顯示

public partial class Content 
{ 
    public Content() 
    { 
     this.Pages = new HashSet<Page>(); 
    } 

    public int ContentID { get; set; } 
    public string ContentTitle { get; set; } 
    public string ContentImage { get; set; } 
    public string ContentImageAlt { get; set; } 
    public string ContentTitleLink { get; set; } 
    public string ContentImageLink { get; set; } 
    public string ContentBody { get; set; } 
    public string ContentTeaser { get; set; } 
    public System.DateTime ContentDate { get; set; } 
    public bool enabled { get; set; } 
    public int SortKey { get; set; } 
    public int ContentTypeID { get; set; } 

    public virtual ContentType ContentType { get; set; } 
    public virtual ICollection<Page> Pages { get; set; } 
} 

的觀點僅僅是

 @foreach (var art in Model.Content) 
     { 
      <text> 
       @Html.DynamicPageContent(art) 
      </text> 
     } 

,並且採用的是幫手

public static MvcHtmlString DynamicPageContent(this HtmlHelper helper, Content content) 
    { 
     if (content.ContentType==null) return new MvcHtmlString(content.ContentBody); 
     return content == null ? null : MvcHtmlString.Create( String.Format("\n<!--{0}: {1}({2})-->\n",content.ContentID, content.ContentType.ContentTypeDescription, content.ContentTypeID)+helper.Partial(content.ContentType.TemplateName, content).ToString().Trim()); 
    } 

其中每個Content.ContentType包含TEMPLATENAME其是MVC視圖名。

所以主視圖然後呈現了一些parital意見。最簡單的部分視圖只包含@Html.Raw(content.Body),其他人使用Content類的屬性渲染更多的結構化內容:我有一個用於託管圖像,一個用於新聞文章等。

然後在你的後端可以使用劍道控件(或其他)編輯ContentBody,ContentTeaser等,只設置一個適當的ContentType這名局部視圖來渲染它。

希望這會給你足夠的讓你開始。

+0

謝謝:) 我的問題,我有一個客戶建立網站,現在的客戶要求修改的網站,因爲他喜歡,修改內容..Images ..等,以及所有視圖通過剃刀 – Jala

+1

唯一建你可以直接做的方式是讓一些代碼讀取剃刀視圖服務器端,並允許編輯這些代碼 - 畢竟它們只是文件,並在運行時編譯。但是,從非內容管理網站轉到內容管理網站最好是通過引入CMS來完成。作爲一個建議,Umbraco基於Razor,允許服務器端對模板進行編輯,對編輯者來說非常好用。但是,它的File:New-Project時間! – Andiih