ASP. NET MVC5 website development management list, reply and delete (13), mvc5 Development Management

Source: Internet
Author: User

ASP. NET MVC5 website development management list, reply and delete (13), mvc5 Development Management

I. Management list
Similar to my list, I directly pasted the code.

First, open the Consultation controller and add the ManageList method.

/// <Summary> /// consulting management /// </summary> /// <returns> </returns> public ActionResult ManageList () {return View ();}

Add ManageJsonList for the returned json data

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() });    }

Right-click ManageList and add an attempt

@ {ViewBag. title = "consulting management";} <div id = "toolbar"> <div> <a href = "#" class = "easyui-linkbutton" data-options = "iconCls: 'icon-delete', plain: true "onclick =" del () "> Delete </a> <a href =" # "class =" easyui-linkbutton "data-options =" iconCls: 'icon-reload', plain: true "onclick =" $ ('# Consultation_List '). datagrid ('reload'); "> refresh </a> </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: 'loading ...... ', FitColumns: true, pagination: true, url:' @ Url. action ("ManageJsonList", "Consultation") ', columns: [[{field: 'modelid', title: 'id', checkbox: true}, {field: 'title', Title: 'title'}, {field: 'inputer', title: 'advisioner ', align: 'right'}, {field: 'releasedate ', title: 'consulting date', align: 'right', formatter: function (value, row, index) {return jsonDateFormat (value) ;},{ field: 'statusstring ', title: 'status', width: 100, align: 'right'}], toolbar: '# toolbar', idField: 'modelid', view: detailview, detailFormatter: function (rowIndex, rowData) {return '<div class = "detail" style = "width: 100%, padding: 5 p x 0"> </div> ';}, onExpandRow: function (index, row) {var detail = $ (this ). datagrid ('getrowdetail ', index ). find ('div. detail '); detail (detail).html ("<iframe frameborder = '0' marginwidth = '0' height = '160px 'width = '000000' src =' @ Url. action ("Reply", "Consultation")/"+ row. modelID + "'> </iframe>"); $ (' # Consultation_List '). datagrid ('fixdetailrowheight', index) ;}}); </script>


2. reply to comments
ManageList adds the datagrid detailed view using the class framework ("<iframe frameborder = '0' marginwidth = '0' height = '160px 'width = '20170' src = '@ Url. action ("Reply", "Consultation")/"+ row. modelID + "'> </iframe> "). "Consultation/Reply" is the view we Reply.

In the Consultation controller, add the Reply Method

/// <Summary> /// reply /// </summary> /// <param name = "id"> id </param> /// <returns> </returns> public ActionResult Reply (int id) {return View (commonModelService. find (id ). consultation );}

Right-click to add view

@ 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> <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> <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> administrator at: @ Model. replyTime: </span> <br/> <p style = "margin-top: 8px"> @ Model. replyContent </p> </td> </tr>} else {<tr> <th> reply @ 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> <th> </th> <td colspan = "3"> <input type = "submit" class = "btn_reply btn- primary "value =" OK "/> </td> </tr >}</table>}

Add the receiving method.

[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", "The reply content is required! "); Else {_ commonModel. consultation. replyContent = Request. form ["ReplyContent"]; _ commonModel. consultation. replyTime = System. dateTime. now; _ commonModel. status = 29; commonModelService. update (_ commonModel) ;}} return View (_ commonModel. consultation );}

The process is:

1. Receive the id parameter in the route (RouteData. Values. ContainsKey ("id "))

2. Search for the CommonModel of the ID, obtain the ReplyContent passed by the client, set other parameters (ReplyTime, Status), and save the value to the database.

3. Return to view

3. delete comments
In the Consultation controller, add the Delete Method

/// <Summary> /// delete comments /// </summary> /// <param name = "id"> Public Model 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);} Then open the ManageList view and add and Delete js Code // Delete function del () {var rows = $ ("# Consultation_List "). Datagrid ("getSelections"); if (! Rows | rows. length <1) {$. messager. alert ("prompt", "no row selected! "); Return;} else if (rows. length> 0) {$. messager. confirm (" OK "," Are you sure you want to delete the selected row? ", Function (r) {if (r) {$. messager. SS (); $. each (rows, function (index, value) {$. ajax ({type: "post", url: "@ Url. action ("Delete", "Consultation") ", data: {id: value. modelID}, async: false, success: function (data) {}}) ;}); $. messager. SS ('close'); // clear the selection row rows. length = 0; $ ("# Consultation_List "). datagrid ('reload') ;}}); return ;}

This time, the content is repeated. The management list is similar to my consulting list. The deletion and reply operations are similar to the article code. The member area is finally written and I hope it will be helpful to you.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.