一.在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: ,
template: '<a href="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="@T("Admin.Common.Save")" />
<input type="submit" name="save-continue" class="btn btn-default" value="@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);
}