ASP.NET MVC5网站开发修改及删除文章(十)(3)

onDblClickRow: function (rowIndex, rowData) { window.parent.addTab("修改文章", "@Url.Action("Edit","Article")/" + rowData.ModelID, "icon-page"); }

2、

ASP.NET MVC5网站开发修改及删除文章(十)

四、我的文章列表
我的文章列表与全部文章类似,并简化掉了部分内容那个,更加简单,直接上代码了
Article控制器中添加

/// <summary> /// 文章列表Json【注意权限问题,普通人员是否可以访问?】 /// </summary> /// <param>标题</param> /// <param>录入</param> /// <param>栏目</param> /// <param>日期起</param> /// <param>日期止</param> /// <param>页码</param> /// <param>每页记录</param> /// <returns></returns> public ActionResult JsonList(string title, string input, Nullable<int> category, Nullable<DateTime> fromDate, Nullable<DateTime> toDate, int pageIndex = 1, int pageSize = 20) { if (category == null) category = 0; int _total; var _rows = commonModelService.FindPageList(out _total, pageIndex, pageSize, "Article", title, (int)category, input, fromDate, toDate, 0).Select( cm => new Ninesky.Web.Models.CommonModelViewModel() { CategoryID = cm.CategoryID, CategoryName = cm.Category.Name, DefaultPicUrl = cm.DefaultPicUrl, Hits = cm.Hits, Inputer = cm.Inputer, Model = cm.Model, ModelID = cm.ModelID, ReleaseDate = cm.ReleaseDate, Status = cm.Status, Title = cm.Title }); return Json(new { total = _total, rows = _rows.ToList() }); } public ActionResult MyList() { return View(); } /// <summary> /// 我的文章列表 /// </summary> /// <param></param> /// <param></param> /// <param></param> /// <param></param> /// <param></param> /// <returns></returns> public ActionResult MyJsonList(string title, Nullable<DateTime> fromDate, Nullable<DateTime> toDate, int pageIndex = 1, int pageSize = 20) { int _total; var _rows = commonModelService.FindPageList(out _total, pageIndex, pageSize, "Article", title, 0, string.Empty, fromDate, toDate, 0).Select( cm => new Ninesky.Web.Models.CommonModelViewModel() { CategoryID = cm.CategoryID, CategoryName = cm.Category.Name, DefaultPicUrl = cm.DefaultPicUrl, Hits = cm.Hits, Inputer = cm.Inputer, Model = cm.Model, ModelID = cm.ModelID, ReleaseDate = cm.ReleaseDate, Status = cm.Status, Title = cm.Title }); return Json(new { total = _total, rows = _rows.ToList() }, JsonRequestBehavior.AllowGet); } 为MyList右键添加视图 <div> <div> <a href="#" data-options="iconCls:'icon-edit',plain:true">修改</a> <a href="#" data-options="iconCls:'icon-remove',plain:true">删除</a> <a href="#" data-options="iconCls:'icon-reload',plain:true">刷新</a> </div> <div> <label>标题</label> <input /> <label>添加日期</label> <input type="datetime" /> - <input type="datetime" /> <a href="#" data-options="iconCls:'icon-search'">查询</a> </div> </div> <table></table> <script src="https://www.jb51.net/~/Scripts/Common.js"></script> <script type="text/javascript"> $("#article_list").datagrid({ loadMsg: '加载中……', pagination:true, url: '@Url.Action("MyJsonList", "Article")', columns: [[ { field: 'ModelID', title: 'ID', checkbox: true }, { field: 'CategoryName', title: '栏目'}, { field: 'Title', title: '标题'}, { field: 'Inputer', title: '录入', align: 'right' }, { field: 'Hits', title: '点击', align: 'right' }, { field: 'ReleaseDate', title: '发布日期', align: 'right', formatter: function (value, row, index) { return jsonDateFormat(value); } }, { field: 'StatusString', title: '状态', width: 100, align: 'right' } ]], toolbar: '#toolbar', idField: 'ModelID', onDblClickRow: function (rowIndex, rowData) { window.parent.addTab("修改文章", "@Url.Action("Edit","Article")/" + rowData.ModelID, "icon-page"); } }); //查找 $("#btn_search").click(function () { $("#article_list").datagrid('load', { title: $("#textbox_title").val(), fromDate: $("#datebox_fromdate").datebox('getValue'), toDate: $("#datebox_todate").datebox('getValue') }); }); //修改事件 function eidt() { var rows = $("#article_list").datagrid("getSelections"); if (!rows || rows.length < 1) { $.messager.alert("提示", "请选择要修改的行!"); return; } else if (rows.length != 1) { $.messager.alert("提示", "仅能选择一行!"); return; } else { window.parent.addTab("修改文章", "@Url.Action("Edit","Article")/" + rows[0].ModelID, "icon-page"); } } //删除 function del() { var rows = $("#article_list").datagrid("getSelections"); if (!rows || rows.length < 1) { $.messager.alert("提示", "未选择任何行!"); return; } else if (rows.length > 0) { $.messager.confirm("确认", "您确定要删除所选行吗?", function (r) { if (r) { $.messager.progress(); $.each(rows, function (index, value) { $.ajax({ type: "post", url: "@Url.Action("Delete", "Article")", data: { id: value.ModelID }, async: false, success: function (data) { } }); }); $.messager.progress('close'); //清除选择行 rows.length = 0; $("#article_list").datagrid('reload'); } }); return; } } </script>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjwszz.html