程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> 05.NopCommerce給Topic表添加排序及類別字段

05.NopCommerce給Topic表添加排序及類別字段

編輯:C#入門知識

在用到Nopcommerce中靜態頁面表時,發現Topic表沒有排序字段和類別字段,導致如果Page文件很多的話,無法區分是哪個類別,為此我稍微擴展了一下字段,在此記錄一下操作流程,方便以後自己查看,同時也分享給我們的朋友!

//=========================================================================== // 新增字段 //=========================================================================== /// <summary> /// 顯示順序 /// </summary> public int DisplayOrder { get; set; } /// <summary> /// 類別名稱 /// </summary> public string CategoryName { get; set; } //===========================================================================

2.管理後台TopicModel實體加上兩個字段DisplayOrder,CategoryName

//=========================================================================== // 新增字段 //=========================================================================== [NopResourceDisplayName("Admin.ContentManagement.Topics.Fields.DisplayOrder")] public int DisplayOrder { get; set; } [NopResourceDisplayName("Admin.ContentManagement.Topics.Fields.CategoryName")] public string CategoryName { get; set; } //===========================================================================

 

3.在資源庫中加入DisplayOrder與CategoryName的顯示名稱

打開網站後台

Admin.ContentManagement.Topics.Fields.DisplayOrder 與Admin.ContentManagement.Topics.Fields.CategoryName 的值是否存在,不存在則添加.

 

Resource name:Admin.ContentManagement.Topics.Fields.DisplayOrder value:排序

Resource name:Admin.ContentManagement.Topics.Fields.CategoryName value:類別名稱

<tr> <td class="adminTitle"> @Html.NopLabelFor(model => model.CategoryName): </td> <td class="adminData"> @Html.EditorFor(model => model.CategoryName) @Html.ValidationMessageFor(model => model.CategoryName) </td> </tr> <tr> <td class="adminTitle"> @Html.NopLabelFor(model => model.DisplayOrder): </td> <td class="adminData"> @Html.EditorFor(model => model.DisplayOrder) @Html.ValidationMessageFor(model => model.DisplayOrder) </td> </tr>

 

 

4.2修改列表View

打開“Nop.Admin”項目 -> 打開Views文件夾 –> “Topic” –> “list.cshtml”

<table class="adminContent"> <tr> <td> @(Html.Telerik().Grid<TopicModel>() .Name("topics-grid") .Columns(columns => { columns.Bound(x => x.SystemName); columns.Bound(x => x.Title); columns.Bound(x => x.CategoryName); columns.Bound(x => x.DisplayOrder); columns.Bound(x => x.IsPasswordProtected) .Template( @<img alt="" src="@Url.Content("~/Administration/Content/images/active-" + item.IsPasswordProtected.ToString().ToLowerInvariant() + ".gif")" /> ) .ClientTemplate("<img alt='' src='" + Url.Content("~/Administration/Content/images/") + "active-<#= IsPasswordProtected #>.gif' />") .Centered() .Width(100); columns.Bound(x => x.IncludeInSitemap) .Template( @<img alt="" src="@Url.Content("~/Administration/Content/images/active-" + item.IncludeInSitemap.ToString().ToLowerInvariant() + ".gif")" /> ) .ClientTemplate("<img alt='' src='" + Url.Content("~/Administration/Content/images/") + "active-<#= IncludeInSitemap #>.gif' />") .Centered() .Width(100); columns.Bound(x => x.Id) .Width(50) .Centered() .Template(x => Html.ActionLink(T("Admin.Common.Edit").Text, "Edit", new { id = x.Id })) .ClientTemplate("<a href=\"Edit/<#= Id #>\">" + T("Admin.Common.Edit").Text + "</a>") .Title(T("Admin.Common.Edit").Text); }) .DataBinding(dataBinding => dataBinding.Ajax().Select("List", "Topic")) .ClientEvents(events => events.OnDataBinding("onDataBinding")) .EnableCustomBinding(true)) </td> </tr> </table>

 

 

5.修改Topic的List的排序,按DisplayOrder的升序來排

 

image

 

6.預覽一下效果

列表界面

image

添加修改界面

image

 

7.小結

對Nop這麼強大的系統,難免會有一些需求沒有考慮太全!沒事,我會把我修改的分享給大家,下班了,明天go on!

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved