Nopcommerce 二次开发2 Admin
Admin
菜单 增加 siteMap.config增加一行
<siteMapNode SystemName="Hotels" nopResource="Admin.Catalog.Hotels" PermissionNames="ManageProducts" controller="Hotel" action="List" IconClass="fa-dot-circle-o"/>
Controllers 增加新控制器
using System; using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using Nop.Admin.Extensions; using Nop.Admin.Models.Blogs; using Nop.Core.Domain.Blogs; using Nop.Core.Domain.Customers; using Nop.Services.Hotels; using Nop.Services.Helpers; using Nop.Services.Localization; using Nop.Services.Security; using Nop.Services.Seo; using Nop.Services.Stores; using Nop.Web.Framework; using Nop.Web.Framework.Controllers; using Nop.Web.Framework.Kendoui; using Nop.Web.Framework.Mvc; namespace Nop.Admin.Controllers { public class HotelController : Controller { #region Fields private readonly IHotelService _hotelService; private readonly ILanguageService _languageService; private readonly IDateTimeHelper _dateTimeHelper; private readonly ILocalizationService _localizationService; private readonly IPermissionService _permissionService; private readonly IUrlRecordService _urlRecordService; private readonly IStoreService _storeService; private readonly IStoreMappingService _storeMappingService; #endregion #region Constructors public HotelController(IHotelService hotelService, ILanguageService languageService, IDateTimeHelper dateTimeHelper, ILocalizationService localizationService, IPermissionService permissionService, IUrlRecordService urlRecordService, IStoreService storeService, IStoreMappingService storeMappingService) { this._hotelService = hotelService; this._languageService = languageService; this._dateTimeHelper = dateTimeHelper; this._localizationService = localizationService; this._permissionService = permissionService; this._urlRecordService = urlRecordService; this._storeService = storeService; this._storeMappingService = storeMappingService; } #endregion // GET: Hotel public ActionResult Index() { return View(); } public ActionResult List() { return View(); } [HttpPost] public ActionResult List(DataSourceRequest command) { var hotels = _hotelService.GetAllHotels(command.Page-1,command.PageSize,true); var gridModel = new DataSourceResult { Data=hotels, Total=hotels.TotalCount }; return Json(gridModel); } } }
视图 增加 List.cshtml
@{ //page title ViewBag.Title = T("Admin.Catalog.Manufacturers").Text; } @Html.AntiForgeryToken() <div class="content-header clearfix"> <h1 class="pull-left"> @T("Admin.Catalog.Manufacturers") </h1> <div class="pull-right"> <a href="@Url.Action("Create")" class="btn bg-blue"> <i class="fa fa-plus-square"></i> @T("Admin.Common.AddNew") </a> </div> </div> <div class="content"> <div class="form-horizontal"> <div class="panel-group"> <div class="panel panel-default panel-search"> <div class="panel-body"> </div> </div> <div class="panel panel-default"> <div class="panel-body"> <div id="hotels-grid"></div> <script> $(document).ready(function() { $("#hotels-grid").kendoGrid({ dataSource: { type: "json", transport: { read: { url: "@Html.Raw(Url.Action("List", "Hotel"))", type: "POST", dataType: "json", data: additionalData } }, schema: { data: "Data", total: "Total", errors: "Errors" }, error: function(e) { display_kendoui_grid_error(e); // Cancel the changes this.cancelChanges(); }, pageSize:10, serverPaging: true, serverFiltering: true, serverSorting: true }, pageable: { refresh: true, pageSizes: [10] }, editable: { confirmation: "@T("Admin.Common.DeleteConfirmation")", mode: "inline" }, scrollable: false, columns: [ { field: "Name", width: 200, title: "酒店名称" }, { field: "Telephone", width: 200, title: "电话" }, { field: "Introduce", title: "介绍" }, { field: "Id", title: "@T("Admin.Common.Edit")", width: 100, template: '<a href="Edit/#=Id#">@T("Admin.Common.Edit")</a>' } ] }); }); </script> <script type="text/javascript"> $(document).ready(function() { //search button //$('#search-manufacturers').click(function() { // //search // var grid = $('#manufacturers-grid').data('kendoGrid'); // grid.dataSource.page(1); //new search. Set page size to 1 // //grid.dataSource.read(); we already loaded the grid above using "page" function // return false; //}); @*$("#@Html.FieldIdFor(model => model.SearchManufacturerName)").keydown(function(event) { if (event.keyCode == 13) { $("#search-manufacturers").click(); return false; } });*@ }); function additionalData() { var data = { }; addAntiForgeryToken(data); return data; } </script> </div> </div> </div> </div> </div>