佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > ASP.NET MVC5網(wǎng)站開(kāi)發(fā)管理列表、回復(fù)及刪除(十三)

ASP.NET MVC5網(wǎng)站開(kāi)發(fā)管理列表、回復(fù)及刪除(十三)

熱門(mén)標(biāo)簽:科大訊飛語(yǔ)音識(shí)別系統(tǒng) 服務(wù)器配置 硅谷的囚徒呼叫中心 網(wǎng)站排名優(yōu)化 地方門(mén)戶(hù)網(wǎng)站 集中運(yùn)營(yíng)管理辦法 阿里云 百度競(jìng)價(jià)排名

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

首先打開(kāi)Consultation控制器,添加ManageList方法

/// summary>
  /// 咨詢(xún)管理
  /// /summary>
  /// returns>/returns>
  public ActionResult ManageList()
  {
   return View();
  }

添加返回json數(shù)據(jù)的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 = "咨詢(xún)管理";
}

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: '標(biāo)題' },
   { field: 'Inputer', title: '咨詢(xún)?nèi)?, align: 'right' },
   { field: 'ReleaseDate', title: '咨詢(xún)?nèi)掌?, align: 'right', formatter: function (value, row, index) { return jsonDateFormat(value); } },
   { field: 'StatusString', title: '狀態(tài)', 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>


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

在Consultation控制器,添加Reply方法

/// summary>
  /// 回復(fù)
  /// /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 回復(fù)如下/span>
     br />
     p style=" margin-top:8px">
      @Model.ReplyContent
     /p>

    /td>
   /tr>
  }
  else
  {
   tr>
    th>
     回復(fù) @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", "必須輸入回復(fù)內(nèi)容!");
    else
    {
     _commonModel.Consultation.ReplyContent = Request.Form["ReplyContent"];
     _commonModel.Consultation.ReplyTime = System.DateTime.Now;
     _commonModel.Status = 29;
     commonModelService.Update(_commonModel);
    }
   }
   return View(_commonModel.Consultation);
  }

過(guò)程是:

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

2、查找該ID的CommonModel,并獲取客戶(hù)端傳過(guò)來(lái)的ReplyContent,設(shè)置其他參數(shù)(ReplyTime,Status)并保存到數(shù)據(jù)庫(kù)

3、返回視圖

三、刪除評(píng)論
在Consultation控制器,添加Delete方法

/// summary>
  /// 刪除評(píng)論
  /// /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);
  }
然后打開(kāi)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("確認(rèn)", "您確定要?jiǎng)h除所選行嗎?", 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網(wǎng)站開(kāi)發(fā)教程》,歡迎大家學(xué)習(xí)閱讀,更多內(nèi)容還可以參考ASP.NET MVC5網(wǎng)站開(kāi)發(fā)專(zhuān)題學(xué)習(xí)。

這次的內(nèi)容比較重復(fù),管理列表類(lèi)似與我的咨詢(xún)列表,刪除、回復(fù)與文章的代碼很類(lèi)似,關(guān)于member區(qū)域終于寫(xiě)完,希望對(duì)大家有所幫助。

您可能感興趣的文章:
  • IIS7/IIS7.5/IIS8網(wǎng)站目錄執(zhí)行權(quán)限設(shè)置方法(與IIS6不同)
  • Win2008 R2中IIS7.5配置完網(wǎng)站權(quán)限不足問(wèn)題的解決方法
  • IIS PHP環(huán)境Temp文件夾的權(quán)限問(wèn)題引起的網(wǎng)站故障
  • win2003 IIS虛擬主機(jī)網(wǎng)站防木馬、權(quán)限設(shè)置、安全配置整理
  • Apache Wind2003 配置網(wǎng)站目錄權(quán)限小結(jié)
  • ASP.NET MVC5網(wǎng)站開(kāi)發(fā)之登錄、驗(yàn)證和注銷(xiāo)管理員篇1(六)
  • ASP.NET MVC5網(wǎng)站開(kāi)發(fā)之實(shí)現(xiàn)數(shù)據(jù)存儲(chǔ)層功能(三)
  • vs2010制作簡(jiǎn)單的asp.net網(wǎng)站
  • 如何對(duì)ASP.NET網(wǎng)站實(shí)現(xiàn)靜態(tài)化
  • MVC網(wǎng)站開(kāi)發(fā)之權(quán)限管理篇

標(biāo)簽:威海 隨州 西雙版納 梧州 烏蘭察布 甘孜 開(kāi)封 廣西

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ASP.NET MVC5網(wǎng)站開(kāi)發(fā)管理列表、回復(fù)及刪除(十三)》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢(xún)

    • 400-1100-266
    松江区| 青龙| 内黄县| 枣强县| 棋牌| 昌平区| 滨州市| 齐齐哈尔市| 双峰县| 厦门市| 宜兰市| 顺义区| 岑巩县| 凤山县| 云浮市| 成安县| 威海市| 中阳县| 奉新县| 工布江达县| 张家界市| 宣汉县| 汽车| 稷山县| 邯郸市| 介休市| 赞皇县| 保山市| 类乌齐县| 噶尔县| 从江县| 于都县| 藁城市| 广灵县| 裕民县| 方城县| 闵行区| 叶城县| 梁山县| 麻栗坡县| 嘉义县|