MVC 中 CMS 的最佳实践是什么?
What is Best Practice of CMS in MVC?
我有一个包含很多视图的 MVC 项目,
我希望客户端将内容编辑为 he/she 喜欢并保存。
如何制作 CMS(内容管理系统)的浏览量?
我在 telerik 中阅读过有关 RedEditor 的信息,但它仅适用于 html 文件,
MVC 是包含 razor 的 cshtml 文件,我无法通过 RedEditor 处理。
我的问题是我为客户建立了一个网站,现在客户要求根据自己的喜好修改网站,修改内容..图像..等,以及由razor建立的所有视图
例如:这是razor制作的页面
我希望管理员客户端修改标题和图片,并在保存后反映在实时网站中
为了在 MVC 中做一个简单的内容管理系统,您可能想要组织一些东西,使页面模型是一个内容项列表,以便您的视图迭代内容项并显示它们
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 视图名称。
因此主视图然后呈现多个分视图。我的部分视图中最简单的只包含@Html.Raw(content.Body),其他视图使用内容 class 的属性呈现更多结构化内容:我有一个用于托管图像,一个用于新闻文章等
然后在您的后端,您可以使用 Kendo 控件(或其他)来编辑 ContentBody、ContentTeaser 等,只需设置一个适当的 ContentType 来命名局部视图以呈现它。
希望这足以让您入门。
我有一个包含很多视图的 MVC 项目, 我希望客户端将内容编辑为 he/she 喜欢并保存。
如何制作 CMS(内容管理系统)的浏览量?
我在 telerik 中阅读过有关 RedEditor 的信息,但它仅适用于 html 文件, MVC 是包含 razor 的 cshtml 文件,我无法通过 RedEditor 处理。
我的问题是我为客户建立了一个网站,现在客户要求根据自己的喜好修改网站,修改内容..图像..等,以及由razor建立的所有视图
例如:这是razor制作的页面 我希望管理员客户端修改标题和图片,并在保存后反映在实时网站中
为了在 MVC 中做一个简单的内容管理系统,您可能想要组织一些东西,使页面模型是一个内容项列表,以便您的视图迭代内容项并显示它们
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 视图名称。
因此主视图然后呈现多个分视图。我的部分视图中最简单的只包含@Html.Raw(content.Body),其他视图使用内容 class 的属性呈现更多结构化内容:我有一个用于托管图像,一个用于新闻文章等
然后在您的后端,您可以使用 Kendo 控件(或其他)来编辑 ContentBody、ContentTeaser 等,只需设置一个适当的 ContentType 来命名局部视图以呈现它。
希望这足以让您入门。