首页 > 代码库 > c# 框架学习(nop )总结-------编辑功能
c# 框架学习(nop )总结-------编辑功能
一.在js中配置列:
<script> $(document).ready(function () { $("#enterprise-grid").kendoGrid({ dataSource: { type: "json", transport: { read: { url: "@Html.Raw(Url.Action("List", "Individual"))", type: "POST", dataType: "json", data: additionalData } }, schema: { data: "Data", total: "Total", errors: "Errors" }, error: function(e) { display_kendoui_grid_error(e); this.cancelChanges(); }, pageSize: @(defaultGridPageSize), serverPaging: true, serverFiltering: true, serverSorting: true }, pageable: { refresh: true, pageSizes: [@(gridPageSizes)] }, editable: { confirmation: false, mode: "inline" }, scrollable: false, columns: [ { field: "Id", title: "@T("Admin.Common.Edit")", width: 50, template: ‘<a href="http://www.mamicode.com/Edit/#=Id#">@T("编辑")</a>‘//通过id传值 }] }); }); </script>
二.控制器中编辑功能实现的方法:
public ActionResult Edit(int id) { var individualEdit = _individualInfoService.GetIndividualInfoById(id);//通过id获取该条数据 if (individualEdit == null) { return RedirectToAction("List"); } var model = individualEdit.ToModel(); return View(model); }
二.1 编辑界面view:
@using NopEnterprise.Admin.Models; @model IndividualInfoModel//数据类型的model @{ //page title ViewBag.Title = T("标题").Text; } @using (Html.BeginForm()) { @Html.AntiForgeryToken() <div class="content-header clearfix"> <h1 class="pull-left"> @T("编辑信息") <small>@Html.ActionLink("(" + T("BackToList") + ")", "List")</small> </h1> <div class="pull-right"> <input type="submit" name="save" class="btn btn-default" value=http://www.mamicode.com/"@T("Admin.Common.Save")" /> <input type="submit" name="save-continue" class="btn btn-default" value=http://www.mamicode.com/"@T("Admin.Common.SaveContinue")" /> <span id="individual-delete" class="btn btn-default">@T("Admin.Common.Delete")</span> </div> </div> @Html.Partial("_CreateOrUpdate", Model) } @Html.DeleteConfirmation("individual-delete")//删除
三.控制器中接收:
[HttpPost, ParameterBasedOnFormName("save-continue", "continueEditing")] public ActionResult Edit(IndividualInfoModel model, bool continueEditing) { ///权限位置(需要添加)var aIndividual = _individualInfoService.GetIndividualInfoById(model.Id); if (aIndividual == null) { return RedirectToAction("List"); } if (ModelState.IsValid) { aIndividual = model.ToEntity(aIndividual); _individualInfoService.UpdateIndividualInfo(aIndividual); SuccessNotification(_localizationService.GetResource("编辑成功")); if (continueEditing) { return RedirectToAction("Edit", new { id = aIndividual.Id }); } return RedirectToAction("List"); } return View(model); }
c# 框架学习(nop )总结-------编辑功能
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。