asp.net MVC5 website Development management list, reply and delete (13) _ Practical Skills

Source: Internet
Author: User

A, management list
similar to my last list, I put the code directly.

First open the consultation controller, add the Managelist method

<summary>
  ///Consulting Management
  ///</summary>
  ///<returns></returns>
  Public ActionResult managelist ()
  {return
   View ();
  }

Add managejsonlist that returns JSON data

Public Jsonresult managejsonlist (int pageIndex = 1, int pageSize =)
  {
   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 for managelist to add an attempt to

@{Viewbag.title = "Consulting Management";} &lt;div id= "Toolbar" &gt; &lt;div&gt; &lt;a href= "#" class= "Easyui-linkbutton" data-options= "iconcls: ' Icon-remove ', Plain:true "onclick=" del () "&gt; Delete &lt;/a&gt; &lt;a href=" # "class=" Easyui-linkbutton "data-options=" ICONCLS: ' Icon-reload ', plain:true "onclick=" $ (' #Consultation_List '). DataGrid (' reload '); &gt; Refresh &lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;table id= "consultation_list" &gt;&lt;/table&gt; &lt;script src= "~/ Scripts/common.js "&gt;&lt;/script&gt; &lt;script src=" ~/scripts/jquery.easyui.datagrid.detailview.js "&gt;&lt;/ script&gt; &lt;script type= "Text/javascript" &gt; $ ("#Consultation_List"). DataGrid ({loadmsg: ' Loading ... ', Fitcolumns:tru  E, pagination:true, url: ' @Url. Action ("Managejsonlist", "consultation") ', columns: [[{field: ' ModelID ', title: ' ID ', checkbox:true}, {field: ' title ', Title: ' Caption '}, {field: ' Inputer ', Title: ' Consulting person ', align: ' right '}, {F Ield: ' ReleaseDate ', title: ' Consultation Date ', align: ' right ', formatter:function(value, row, index) {return Jsondateformat (value);} }, {field: ' Statusstring ', title: ' State ', width:100, align: ' right '}], toolbar: ' #toolbar ', IDfield: ' ModelID ' , View:detailview, Detailformatter:function (RowIndex, RowData) {return ' &lt;div class= ' detail ' style= ' width:100%,p adding:5px 0 "&gt;&lt;/div&gt;";
   }, Onexpandrow:function (index, row) {var detail = $ (this). DataGrid (' Getrowdetail ', index). Find (' Div.detail '); $ (detail). html ("&lt;iframe frameborder= ' 0 ' marginwidth= ' 0 ' height= ' 160px ' width= ' 100% ' src= '" @Url. Action ("Reply", " Consultation ")/" + row.
   ModelID + "' &gt;&lt;/iframe&gt;");
  $ (' #Consultation_List '). DataGrid (' Fixdetailrowheight ', index);

}
 }); &lt;/script&gt;


Ii. Reply to comments
Managelist add DataGrid Detail View Use class Framework ("<iframe frameborder= ' 0 ' marginwidth= ' 0 ' height= ' 160px ' width= ' 100% ' ' src= '" @ Url.action ("Reply", "consultation")/"+ row." ModelID + "' ></iframe>"). "Consultation/reply" is the view we reply to.

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 a view

@model Ninesky.Models.Consultation @using (Html.BeginForm ()) {@Html. AntiForgeryToken () &lt;table style= "width:100%; font-size:12px; " &gt; &lt;tr&gt; &lt;th&gt; @Html. Displaynamefor (model =&gt; model. Name) &lt;/th&gt; &lt;td&gt; @Html. Displayfor (model =&gt; model. Name) &lt;/td&gt; &lt;th&gt; @Html. Displaynamefor (model =&gt; model. IsPublic) &lt;/th&gt; &lt;td&gt; @Html. Displayfor (model =&gt; model. IsPublic) &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt; @Html. Displaynamefor (model =&gt; model. QQ) &lt;/th&gt; &lt;td&gt; @Html. Displayfor (model =&gt; model. QQ) &lt;/td&gt; &lt;th&gt; @Html. Displaynamefor (model =&gt; model. Email) &lt;/th&gt; &lt;td&gt; @Html. Displayfor (model =&gt; model. Email) &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt; @Html. Displaynamefor (model =&gt; model. Content) &lt;/th&gt; &lt;td colspan= "3" &gt; @Html. Displayfor (model =&gt; model. Content) &lt;/td&gt; &lt;/tr&gt; @if (model.replytime!= null) {&lt;tr&gt; &LT;TD colspan= "4" &gt; &LT;span&gt; admin: @Model. replytime reply as follows &lt;/span&gt; &lt;br/&gt; &lt;p style= "margin-top:8px" &gt; @Model. Re Plycontent &lt;/p&gt; &lt;/td&gt; &lt;/tr&gt;} else {&lt;tr&gt; &lt;th&gt; reply @Html. Hidde Nfor (model =&gt; model. Consultationid) @Html. Validationmessagefor (Model=&gt;model. Consultationid) &lt;/th&gt; &lt;td colspan= "3" &gt; @Html. Textareafor (model =&gt; model. Replycontent, new {@class = "Form-control"}) @Html. Validationmessagefor (Model=&gt;model.
     replycontent) &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;th&gt; &lt;/th&gt; &lt;td colspan= "3" &gt; &lt;input type= "Submit" class= "btn_reply btn btn-primary" value= "OK"/&gt; &lt;/td&gt; &lt;/tr&gt;} &lt;/table

 &gt;}

Add a method for receiving processing.

[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", "must enter the reply content!") ");
    else
    {
     _commonmodel.consultation.replycontent = request.form["Replycontent"];
     _commonmodel.consultation.replytime = System.DateTime.Now;
     _commonmodel.status =;
     Commonmodelservice.update (_commonmodel);
    }
   Return View (_commonmodel.consultation);
  }

The process is:

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

2, look for the commonmodel of the ID, and get the replycontent of the client, set other parameters (Replytime,status) and save it to the database.

3. Return to view

Iii. deletion of comments
In the consultation controller, add the Delete method

&lt;summary&gt;///Delete comments///&lt;/summary&gt;///&lt;param name= "IDs" &gt; Public models id&lt;/param&gt;///&lt;returns
   &gt;&lt;/returns&gt; 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 managelist view, add delete JS code//delete function del () {var rows = $ ("#Consultation_List"). DataGrid ("Getselections");
   if (!rows | | Rows.length &lt; 1) {$.messager.alert ("hint", "No row selected!");
  Return else if (Rows.length &gt; 0) {$.messager.confirm ("Confirm", "Are you sure you want to delete the selected row?)
     ", function (r) {if (R) {$.messager.progress (); $.each (rows, function (index, value) {$.ajax ({type: Post), url: "@Url. Action (" Delete "," Consultatio n ")", data: {id:value.
     ModelID}, Async:false, Success:function (data) {}});
     }); $.messager.progress (' CloSe ');
     Clear Select row Rows.length = 0;
    $ ("#Consultation_List"). DataGrid (' reload ');
   }
   });
  Return
 }

This article has been organized into the "ASP.net MVC Web Development Course", welcome you to learn to read, more content can also refer to asp.net MVC5 website Development topic study.

This time the content is more repetitive, the management list similar to my consulting list, delete, reply and the article code is very similar, about the member area finally finished, hope to help everyone.

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.