您的位置:首页> 日志> 动易系统 正文

    2016年最后一个月12月份,一个用新系统制作的四川地方志的新项目就占据了主要时间,今天就谈谈新系统创建内容模型的步骤方法吧!

第一:创建内容模型,操作:平台管理=>内容管理设置=>内容模型管理=>创建内容模型

 

第二:添加扩展字段

 

  

 

第三:编辑后台模板(可参考系统默认新增的领导模型)

   (1)从第一步中可以看出,完全定制一个内容模型要编辑新的四个后台模板(列表页模板、创建页模板、修改页模板、查看页模板),其中必须的有两个,其它次要!这也是相应增加了时间成本!如果以后手机版后台也要实现的话,也得继续新增手机版的四个后台管理模板!

 

   (2)创建页模板(Create.cshtml)和修改页模板(Modify.cshtml),这两个模板新内容模型的扩展字段有关!

     a. 后台模板路径:\Admin\Views\ContentManage

     b.例如:我新增的人才模型,则在此栏目中新增个 Talents 目录,里面放对应的后台管理模板!

     c.创建页模板(Create.cshtml)

  1. @model Article 
  2. @{ 
  3.     Layout = "~/Admin/Views/ContentManage/Shared/_ArticleCreateLayout.cshtml"
  4.     var isLink = Convert.ToBoolean(Request["islink"]) || !string.IsNullOrEmpty(Model.LinkUrl); 
  5.  
  6. @section formcontent 
  7.     @Html.RowEditorFor(c => c.Title) 
  8.     @Html.HiddenFor(a => a.Content, new { Value = "暂无" }) 
  9.     @Html.RowEditorFor(a => a.NodeId) 
  10.     @* 扩展字段 S*@ 
  11.     @Html.RowEditorForExtendField("sex"
  12.     @Html.RowEditorForExtendField("date"
  13.     @Html.RowEditorForExtendField("education"
  14.     @Html.RowEditorForExtendField("work"
  15.     @Html.RowEditorForExtendField("job"
  16.     @Html.RowEditorForExtendField("zyyjfx"
  17.     @Html.RowEditorForExtendField("research"
  18.     @* 扩展字段 E*@ 
  19.     @Html.RowEditorFor(a => a.FeaturedImage) 
  20.     @Html.RowEditorFor(a => a.Hits) 
  21.     @Html.RowEditorFor(a => a.Priority) 
  22.     @Html.RowEditorFor(a => a.PublishTime) 
  23.     @Html.RowEditorFor(a => a.ContentViewPath) 

     d.修改页模板(Modify.cshtml)

  1. @model Article 
  2. @{ 
  3.     Layout = "~/Admin/Views/ContentManage/Shared/_ArticleModifyLayout.cshtml"
  4.  
  5. @section formcontent 
  6.     @Html.HiddenFor(a => a.ContentId) 
  7.     @Html.RowEditorFor(a => a.Title) 
  8.     @Html.HiddenFor(a => a.Content, new { Value = "暂无" }) 
  9.     @Html.RowEditorFor(a => a.NodeId) 
  10.     @* 扩展字段 S*@ 
  11.     @Html.RowEditorForExtendField("sex"
  12.     @Html.RowEditorForExtendField("date"
  13.     @Html.RowEditorForExtendField("education"
  14.     @Html.RowEditorForExtendField("work"
  15.     @Html.RowEditorForExtendField("job"
  16.     @Html.RowEditorForExtendField("zyyjfx"
  17.     @Html.RowEditorForExtendField("research"
  18.     @* 扩展字段 E*@ 
  19.     @Html.RowEditorFor(a => a.FeaturedImage) 
  20.     @Html.RowEditorFor(a => a.Hits) 
  21.     @Html.RowEditorFor(a => a.Priority) 
  22.     @Html.RowEditorFor(a => a.PublishTime) 
  23.     @Html.RowEditorFor(a => a.ContentViewPath) 

上面两个后台模板需要注意的是:它们所属类别不同时:

Layout = "~/Admin/Views/ContentManage/Shared/_ArticleCreateLayout.cshtml";

Layout = "~/Admin/Views/ContentManage/Shared/_ArticleModifyLayout.cshtml";

这里的_ArticleCreateLayout.cshtml 和 _ArticleModifyLayout.cshtml 也是不一样的!

 

第四:编辑相应标签和前台模板!

    (1)人才图片列表.cshtml

  1. @model Article 
  2. @{ 
  3.     //参数 
  4.     int TitleLength = Param.TitleLength ?? 50; //标题 
  5.     int ImageWidth = Param.ImageWidth ?? 320; // 图片宽度 
  6.     int ImageHeight = Param.ImageHeight ?? 240; // 图片高度 
  7. @if (Row.Index == 0) 
  8.     <li class="noData">暂无资料</li> 
  9.     return; 
  10. <li class="@Row.PositionLiteral @Row.IntervalLiteral @Row.HighRankLiteral"> 
  11.     <div class="pic"> 
  12.         <a href="@Model.ContentUrl()" target="@(Param.LinkBlankTarget ?? false ? "_blank" : null)"> 
  13.  
  14.             @if (string.IsNullOrEmpty(Model.FeaturedImage)) 
  15.             { 
  16.                 <img alt="@Model.Title" src="~/Content/_Common/Base/img/nopic.gif" 
  17. width="@ImageWidth" height="@ImageHeight" /> 
  18.             } 
  19.             else 
  20.             { 
  21.                 <img alt="@Model.Title" 
  22. src="@Power.Thumbnail(Model.FeaturedImage.ToUrl(), ImageWidth, ImageHeight)" 
  23. width="@ImageWidth" height="@ImageHeight" /> 
  24.             } 
  25.  
  26.         </a> 
  27.     </div> 
  28.     <div class="title"> 
  29.         <a target="@(Param.LinkBlankTarget ?? false ? "_blank" : null)" 
  30. class="tit" href="@Model.ContentUrl()" title="@Model.Title">@Model.Title.CutText(TitleLength, "…")</a> 
  31.     </div> 
  32.     <div class="job">@Model.ExtendObject.job</div> 
  33.     <span class="titleBg"></span> 
  34. </li> 

   此处需要注意的是扩展字段调用时需要在前面加多 .ExtendObject  例如:@Model.ExtendObject.job

   (2)视图标签调用:

此处需要注意的是:当视图标签中有扩展字段是需要加入这个参数  ExtendField = true,

    (3)人才-内容页.cshtml

  1. @* 内容页模板 *@ 
  2. @model Article 
  3. @{ 
  4.     Layout = "~/Views/Main/Layout/公共布局页.cshtml"
  5.     var service = new ArticleService(); 
  6. @section header { 
  7.     <link href="@Url.AppendVersion("~/Content/Main/ContentManage/css/page.css")" 
  8. rel="stylesheet" /> 
  9. <!-- content S --> 
  10. <div id="content"> 
  11.     <!-- side S --> 
  12.     <aside class="side"> 
  13.         <div id="sideMenu"> 
  14.             <div class="hd"> 
  15.                 <h3>@Model.Node.NodeName</h3> 
  16.             </div> 
  17.             <div class="bd"> 
  18.                 <ul class="menuList"> 
  19.                     @Power.ArticleList("人才标题列表", new { Node = Model.Node, Count = 12
  20. Sort = "Priority DESC,PublishTime DESC,ContentId DESC", TitleLength = 48  }) 
  21.                 </ul> 
  22.             </div> 
  23.         </div> 
  24.         <script> 
  25.             if (jQuery("#sideMenu .bd li").size() === 0) { 
  26.                 jQuery("#sideMenu").hide(); 
  27.             } 
  28.         </script> 
  29.     </aside> 
  30.     <!-- side E --> 
  31.     <!-- mainContent S --> 
  32.     <div class="mainContent"> 
  33.         <div class="mainBox" id="talentsMainBox"> 
  34.             <div class="mHd"> 
  35.                 <div class="path fl">@Power.Partial("位置导航", new { Model.Node })&gt;<span>详细内容</span></div> 
  36.             </div> 
  37.             <div class="mBd"> 
  38.                 <!-- 正文内容 S --> 
  39.                 <article class="talentsCon"> 
  40.                     <div class="printTalents" data-power-area='content'> 
  41.                         <div class="picTit"> 
  42.                             <div class="pic"><img src="@Model.FeaturedImage.ToUrl()" alt="@Model.Title"></div>  
  43.                             <h2 class="title">@Model.Title</h2> 
  44.                         </div> 
  45.                         <!-- 标题 --> 
  46.                         <ul class="con"> 
  47.                             <li> 
  48.                                 <label class="label">职务(职称):</label> 
  49.                                 <div class="info">@Model.ExtendObject.job</div> 
  50.                             </li> 
  51.                             <li> 
  52.                                 <label class="label">单位:</label> 
  53.                                 <div class="info">@Model.ExtendObject.work</div> 
  54.                             </li> 
  55.                             <li> 
  56.                                 <label class="label">性别:</label> 
  57.                                 <div class="info">@Model.ExtendObject.sex</div> 
  58.                             </li> 
  59.                             <li> 
  60.                                 <label class="label">出生年月:</label> 
  61.                                 <div class="info">@Model.ExtendObject.date.ToString("yyyy年MM月")</div> 
  62.                             </li> 
  63.                             <li> 
  64.                                 <label class="label">学历(学位):</label> 
  65.                                 <div class="info">@Model.ExtendObject.education</div> 
  66.                             </li> 
  67.                             <li> 
  68.                                 <label class="label">主要研究方向:</label> 
  69.                                 <div class="info">@Power.ToHtml(Model.ExtendObject.zyyjfx)</div> 
  70.                             </li> 
  71.                             <li> 
  72.                                 <label class="label">研究成果:</label> 
  73.                                 <div class="info">@Power.ToHtml(Model.ExtendObject.research)</div> 
  74.                             </li> 
  75.                         </ul> 
  76.                     </div> 
  77.                 </article> 
  78.                 <!-- 正文内容 E --> 
  79.             </div> 
  80.         </div> 
  81.     </div> 
  82.     <!-- mainContent E --> 
  83. </div> 
  84. <!-- content E --> 
  85. @section scripts{ 
  86.     <script src="@Url.AppendVersion("~/Content/_Common/Assets/Scripts/jquery.PrintArea.js")"></script> 
  87.     <script src="@Url.AppendVersion("~/Content/_Common/Base/js/article.js")"></script> 

     此处调用的扩展字段跟标签上同理加上.ExtendObject

   好了,完毕收工!