ASP .净MVC5网站开发管理列表、回复及删除(十三)
一、管理列表跟上次我的列表相似,直接贴代码了。
首先打开咨询控制器,添加管理列表方法
///摘要///咨询管理////summary////returns/returns public ActionResult managerlist(){ return View();}添加返回json数据的ManageJsonList
public JsonResult ManageJsonList(int page index=1,int page size=20){ int _ total;var _list=commonModelService .查找页面列表(out _total,页面索引,页面大小,'咨询',字符串。空,0,字符串。空,空,空,0)。ToList().选择(厘米=新的尼尼微网络。模特。commonmodelviewmodel(){ CategoryID=cm .CategoryID,CategoryName=cm .类别。名称,DefaultPicUrl=cm .默认图片,点击量=厘米.点击,输入=厘米。输入器,型号=厘米。模型,ModelID=cm .模型号,发布日期=厘米.发布日期,状态=厘米。状态,标题=厘米标题});返回Json(new { total=_total,rows=_list .to list()});}右键为管理列表添加试图
@{ ViewBag .Title='咨询管理;} div id=' toolbar ' div a href=' # ' class=' measuri-link button ' data-options=' iconcl s 3360 ' icon-remove ',plain:true' onclick='del()'删除/a a href=' # ' class=' measuri-link button ' data-options=' iconcl s 3360 ' icon-reload ',plain : true ' onclick=' $(' # consulting _ List ').datagrid(' reload ');'刷新/a/div/div表id=' consulting _ List '/表脚本src=' http : ~/Scripts/common。js '/script script src=' http : ~/Scripts/jquery。苏西。数据网格。详细视图。js '/script脚本类型=' text/JavaScript ' $(' # consulting _ List ').datagrid({ loadMsg: '加载中……',fitColumns: true,pagination: true,url: ' @ Url .操作(“ManageJsonList”、“Consultation”)”,列: [[ { field: 'ModelID ',title: 'ID ',checkbox: true },{ field: 'Title ',title: '标题},{ field: 'Inputer ',title: '咨询人,align: 'right' },{ field: 'ReleaseDate ',title: '咨询日期,对齐: '右',格式器:函数(值、行、索引){返回jsonDateFormat(值);} },{ field: 'StatusString ',title: '状态,width: 100,align: 'right' } ],toolbar: '#toolbar ',idField: 'ModelID ',view: detailview,detailFormatter:函数(rowIndex,row data){ return ' div class=' detail ' style=' width 3360100%,padd :5 px 0 '/div ';},onExpandRow:函数(索引,行){ var detail=$(this).datagrid('getRowDetail ',索引)。find(' div。细节’);$(详细信息)。html(' iframe框架边框=' 0 '边距宽度=' 0 '高度=' 160 px '宽度=' 100% ' src=' @ Ul .操作("回复"、"咨询")/"行模型id " "/iframe ');$(' #咨询列表').datagrid('fixDetailRowHeight ',索引);} });/脚本
二、回复评论管理列表添加数据网格详细视图使用类框架(“iframe框架边框=' 0 '边距宽度=' 0 '高度=' 160 px '宽度=' 100% ' src=' @ Ul .操作("回复"、"咨询")/"行ModelID ''/iframe ' ')。"咨询/回复"就是我们回复的视图。
在咨询控制器,添加回答方法
///摘要///回复////summary////param name=' id ' id/param///returns/returns public action response(int id){ return View(commonModelService .查找(身份证).协商);}右键添加视图
@模型尼尼微。模型。咨询@使用(Html .begin inform()){ @ Html .反伪造令牌()表格样式=“宽度:100%;”font-size :12 pxtr th@Html .显示名称(型号=型号.名称)/th td@Html .显示(模型=模型.名称)/td th@Html .显示名称(型号=型号.IsPublic)/th td@Html .显示(模型=模型.IsPublic)/td /tr tr th@Html .显示名称(型号=型号.QQ)/th td@Html .显示(模型=模型.QQ)/td th@Html .显示名称(型号=型号.电子邮件)/th td@Html .显示(模型=模型.电子邮件)/td /tr tr th@Html .显示名称(型号=型号.Content)/th td colspan='3'@Html .显示(模型=模型.内容)/td /tr @if(型号。回复时间!=null) { tr td colspan='4' span管理员于:@模型。回复时间回复如下/span br/p style=' margin-top :8 px ' @ Model .ReplyContent /p /td /tr } else { tr th回复@Html .HiddenFor(model=model .ConsultationID) @Html .ValidationMessageFor(model=model .咨询id)/th TD col span=' 3 ' @ Html .textarefor(model=model .ReplyContent,new { @ class=' form-control ' })@ Html .ValidationMessageFor(model=model .回复内容)/TD/tr th/th TD colspan=' 3 '输入类型=' submit ' class=' BTN _ reply BTN BTN-primary ' value='确定//td /tr } /table}添加接收处理的方法。
[httpset][validateantforgretoken]公共操作结果Reply(){ common model _ common model=null;if(路由数据.价值观。包含KeY(' id '){ int _ MoDEL id=int .解析(路由数据。值['id'].ToString());_通用模型=通用模型服务.find(_ modelId);如果(字符串IsNullOrEmpty(请求。表单['ReplyContent'])) ModelState .addmodelarrror('回复内容','必须输入回复内容!');else { _commonModel .咨询。回复内容=请求。表单['回复内容'];_commonModel .咨询。回复时间=系统。日期时间。现在;_commonModel .状态=29;commonModelService .update(_ common model);} }返回视图(_commonModel .协商);}过程是:
1、接收路由中的编号参数(路由数据.值。包含密钥(“id”)
2、查找该身份的CommonModel,并获取客户端传过来的回复内容,设置其他参数(回复时间,状态)并保存到数据库
3、返回视图
三、删除评论在咨询控制器,添加删除方法
///摘要///删除评论////summary ///param name='id '公共模型ID/param////返回/返回公共操作结果Delete(int ID){ var _ common model=common model service .find(id);if (_commonModel==null)返回Json(假);if (commonModelService .删除(_commonModel))返回Json(真);其他返回Json(假);}然后打开管理列表视图,添加删除射流研究…代码//删除function del(){ var rows=$(' # consulting _ List ').数据网格(' GetSelections ');if(!行| |行。长度1){ $。信使。警报('提示', '未选择任何行!');返回;} else if(row。长度0){ $。信使。确认('确认', '您确定要删除所选行吗?',函数(r){ if(r){ $。信使。progress();$.每一个(行,函数(索引,值){ $。ajax({ type: 'post ',url: ' @ Url .操作('删除','咨询'),数据: { id:值模型标识},async:假,成功:函数(数据){ } });});$ .信使。进度('关闭');//清除选择行行。长度=0;$(' #咨询列表').datagrid(' reload ');} });返回;}本文已被整理到了《ASP.NET MVC网站开发教程》 ,欢迎大家学习阅读,更多内容还可以参考ASP .净MVC5网站开发专题学习。
这次的内容比较重复,管理列表类似与我的咨询列表,删除、回复与文章的代码很类似,关于成员区域终于写完,希望对大家有所帮助。
版权声明:ASP .净MVC5网站开发管理列表、回复及删除(十三)是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。