校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

主頁 > 知識庫 > ASP.NET MVC5網站開發管理列表、回復及刪除(十三)

ASP.NET MVC5網站開發管理列表、回復及刪除(十三)

熱門標簽:聊城智能電銷機器人電話 安陸市地圖標注app 海東防封電銷卡 辦公用地圖標注網點怎么操作 寧德防封版電銷卡 西寧電銷外呼系統公司 南昌自動外呼系統線路 云南外呼系統代理 上海市三維地圖標注

一、管理列表
跟上次我的列表相似,直接貼代碼了。

首先打開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 id="toolbar">
 div>
  a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="del()">刪除/a>
  a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true" onclick="$('#Consultation_List').datagrid('reload');">刷新/a>
 /div>
/div>

table id="Consultation_List">/table>

script src="~/Scripts/Common.js">/script>
script src="~/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 class="detail" style="width:100%,padding:5px 0">/div>'; },
  onExpandRow: function (index, row) {
   var detail = $(this).datagrid('getRowDetail', index).find('div.detail');
   $(detail).html("iframe frameborder='0' marginwidth='0' height='160px' width='100%' src='@Url.Action("Reply", "Consultation")/" + row.ModelID + "'>/iframe>");
   $('#Consultation_List').datagrid('fixDetailRowHeight', index);
  }
 });

/script>


二、回復評論
ManageList添加datagrid詳細視圖使用類框架(("iframe frameborder='0' marginwidth='0' height='160px' width='100%' src='@Url.Action("Reply", "Consultation")/" + row.ModelID + "'>/iframe>")。“Consultation/Reply”就是我們回復的視圖。

在Consultation控制器,添加Reply方法

/// summary>
  /// 回復
  /// /summary>
  /// param name="id">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 style="width:100%;font-size:12px;">
  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 style=" margin-top:8px">
      @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" class="btn_reply btn btn-primary" value="確定" />
    /td>
   /tr>
  }
 /table>
}

添加接收處理的方法。

[HttpPost]
  [ValidateAntiForgeryToken]
  public ActionResult Reply()
  {
   CommonModel _commonModel = null;
   if (RouteData.Values.ContainsKey("id"))
   {
    int _modelId = int.Parse(RouteData.Values["id"].ToString());
    _commonModel = commonModelService.Find(_modelId);
    if (string.IsNullOrEmpty(Request.Form["ReplyContent"])) ModelState.AddModelError("ReplyContent", "必須輸入回復內容!");
    else
    {
     _commonModel.Consultation.ReplyContent = Request.Form["ReplyContent"];
     _commonModel.Consultation.ReplyTime = System.DateTime.Now;
     _commonModel.Status = 29;
     commonModelService.Update(_commonModel);
    }
   }
   return View(_commonModel.Consultation);
  }

過程是:

1、接收路由中的id參數(RouteData.Values.ContainsKey("id"))

2、查找該ID的CommonModel,并獲取客戶端傳過來的ReplyContent,設置其他參數(ReplyTime,Status)并保存到數據庫

3、返回視圖

三、刪除評論
在Consultation控制器,添加Delete方法

/// summary>
  /// 刪除評論
  /// /summary>
  /// param name="id">公共模型ID/param>
  /// returns>/returns>
  public ActionResult Delete(int id)
  {
   var _commonModel = commonModelService.Find(id);
   if (_commonModel == null) return Json(false);

   if (commonModelService.Delete(_commonModel)) return Json(true);
   else return Json(false);
  }
然后打開ManageList視圖,添加刪除js代碼
//刪除
 function del() {
  var rows = $("#Consultation_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", "Consultation")",
       data: { id: value.ModelID },
       async: false,
       success: function (data) {
       }
      });
     });
     $.messager.progress('close');
     //清除選擇行
     rows.length = 0;
     $("#Consultation_List").datagrid('reload');
    }
   });
   return;
  }

本文已被整理到了《ASP.NET MVC網站開發教程》,歡迎大家學習閱讀,更多內容還可以參考ASP.NET MVC5網站開發專題學習。

這次的內容比較重復,管理列表類似與我的咨詢列表,刪除、回復與文章的代碼很類似,關于member區域終于寫完,希望對大家有所幫助。

您可能感興趣的文章:
  • IIS7/IIS7.5/IIS8網站目錄執行權限設置方法(與IIS6不同)
  • Win2008 R2中IIS7.5配置完網站權限不足問題的解決方法
  • IIS PHP環境Temp文件夾的權限問題引起的網站故障
  • win2003 IIS虛擬主機網站防木馬、權限設置、安全配置整理
  • Apache Wind2003 配置網站目錄權限小結
  • ASP.NET MVC5網站開發之登錄、驗證和注銷管理員篇1(六)
  • ASP.NET MVC5網站開發之實現數據存儲層功能(三)
  • vs2010制作簡單的asp.net網站
  • 如何對ASP.NET網站實現靜態化
  • MVC網站開發之權限管理篇

標簽:汕尾 崇左 平涼 南寧 青海 洛陽 衢州 贛州

巨人網絡通訊聲明:本文標題《ASP.NET MVC5網站開發管理列表、回復及刪除(十三)》,本文關鍵詞  ASP.NET,MVC5,網站開發,管理,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《ASP.NET MVC5網站開發管理列表、回復及刪除(十三)》相關的同類信息!
  • 本頁收集關于ASP.NET MVC5網站開發管理列表、回復及刪除(十三)的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 大新县| 囊谦县| 溆浦县| 方城县| 古交市| 温州市| 新乐市| 兴城市| 河源市| 营口市| 抚顺县| 巧家县| 遂宁市| 云霄县| 滦南县| 石门县| 新巴尔虎右旗| 滨海县| 浮梁县| 甘孜县| 嘉兴市| 高平市| 鄂伦春自治旗| 牟定县| 高清| 横峰县| 湖北省| 荥阳市| 崇阳县| 尚义县| 永春县| 卢氏县| 综艺| 郧西县| 阜新| 哈巴河县| 新蔡县| 英吉沙县| 秦皇岛市| 方城县| 阳信县|