一、管理列表
跟上次我的列表相似,直接贴代码了。
首先打开Consultation控制器,添加ManageList方法
/// <summary> /// 咨询管理 /// </summary> /// <returns></returns> public ActionResult ManageList() { return View(); }
添加返回json数据的ManageJsonList
public JsonResult ManageJsonList(int pageIndex = 1, int pageSize = 20) { int _total; var _list = commonModelService.FindPageList(out _total, pageIndex, pageSize, "Consultation", string.Empty, 0, string.Empty, null, null, 0).ToList().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 = _list.ToList() }); }
右键为ManageList添加试图
@{ ViewBag.Title = "咨询管理"; } <div> <div> <a href="#" data-options="iconCls:'icon-remove',plain:true">删除</a> <a href="#" data-options="iconCls:'icon-reload',plain:true">刷新</a> </div> </div> <table></table> <script src="https://www.jb51.net/~/Scripts/Common.js"></script> <script src="https://www.jb51.net/~/Scripts/jquery.easyui.datagrid.detailview.js"></script> <script type="text/javascript"> $("#Consultation_List").datagrid({ loadMsg: '加载中……', fitColumns: true, pagination: true, url: '@Url.Action("ManageJsonList", "Consultation")', columns: [[ { field: 'ModelID', title: 'ID', checkbox: true }, { field: 'Title', title: '标题' }, { field: 'Inputer', 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', view: detailview, detailFormatter: function (rowIndex, rowData) { return '<div></div>'; }, onExpandRow: function (index, row) { var detail = $(this).datagrid('getRowDetail', index).find('div.detail'); $(detail).html("<iframe frameborder='0' marginwidth='0' src='@Url.Action("Reply", "Consultation")/" + row.ModelID + "'></iframe>"); $('#Consultation_List').datagrid('fixDetailRowHeight', index); } }); </script>
二、回复评论
ManageList添加datagrid详细视图使用类框架(("<iframe frameborder='0' marginwidth='0' src='@Url.Action("Reply", "Consultation")/" + row.ModelID + "'></iframe>")。“Consultation/Reply”就是我们回复的视图。
在Consultation控制器,添加Reply方法
/// <summary> /// 回复 /// </summary> /// <param>id</param> /// <returns></returns> public ActionResult Reply(int id) { return View(commonModelService.Find(id).Consultation); }
右键添加视图
@model Ninesky.Models.Consultation @using (Html.BeginForm()) { @Html.AntiForgeryToken() <table> <tr> <th>@Html.DisplayNameFor(model => model.Name)</th> <td>@Html.DisplayFor(model => model.Name)</td> <th>@Html.DisplayNameFor(model => model.IsPublic)</th> <td>@Html.DisplayFor(model => model.IsPublic)</td> </tr> <tr> <th>@Html.DisplayNameFor(model => model.QQ)</th> <td>@Html.DisplayFor(model => model.QQ)</td> <th>@Html.DisplayNameFor(model => model.Email)</th> <td>@Html.DisplayFor(model => model.Email)</td> </tr> <tr> <th>@Html.DisplayNameFor(model => model.Content)</th> <td colspan="3">@Html.DisplayFor(model => model.Content)</td> </tr> @if (Model.ReplyTime != null) { <tr> <td colspan="4"> <span>管理员于:@Model.ReplyTime 回复如下</span> <br /> <p> @Model.ReplyContent </p> </td> </tr> } else { <tr> <th> 回复 @Html.HiddenFor(model => model.ConsultationID) @Html.ValidationMessageFor(model=>model.ConsultationID) </th> <td colspan="3"> @Html.TextAreaFor(model => model.ReplyContent, new { @class = "form-control" }) @Html.ValidationMessageFor(model=>model.ReplyContent) </td> </tr> <tr> <th> </th> <td colspan="3"> <input type="submit" value="确定" /> </td> </tr> } </table> }
添加接收处理的方法。