Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand ASP.NET MVC5 website development management list, reply and delete

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to understand the ASP.NET MVC5 website development management list, reply and delete". The content in the article is simple and clear, easy to learn and understand. Please follow the editor's train of thought to study and learn "how to understand the ASP.NET MVC5 website development management list, reply and delete"!

I. manage the list

Similar to my list last time, I posted the code directly.

First open the Consultation controller and add the ManageList method

/ Consulting Management / public ActionResult ManageList () {return View ();}

Add ManageJsonList that returns 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 to add an attempt for ManageList

@ {ViewBag.Title = "Consulting Management";} Refresh $("# 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:' consultant', align: 'right'}, {field:' ReleaseDate', title: 'consultation 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';}, onExpandRow: function (index, row) {var detail = $(this) .datagrid ('getRowDetail', index) .find (' div.detail'); $(detail) .html (") ('# Consultation_List') .datagrid ('fixDetailRowHeight', index);}})

Second, reply to comments

ManageList adds the datagrid detail view using the class framework ((")." Consultation/Reply "is the view we replied to.

In the Consultation controller, add the Reply method

/ reply / id / 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 () @ Html.DisplayNameFor (model = > model.Name) @ Html.DisplayFor (model = > model.Name) @ Html.DisplayNameFor (model = > model.IsPublic) @ Html.DisplayFor (model = > model.IsPublic) @ Html.DisplayNameFor (model = > model.QQ) @ Html.DisplayFor (model = > model.QQ) @ Html.DisplayNameFor (model = > model.Email) @ Html.DisplayFor (model = > model.Email) @ Html.DisplayNameFor (model = > model.Content) @ Html.DisplayFor (model = > model.Content) @ if (Model.ReplyTime! = null) {the administrator replied at: @ Model.ReplyTime as follows @ Model.ReplyContent

} else {reply @ Html.HiddenFor (model= > model.ConsultationID) @ Html.ValidationMessageFor (model= > model.ConsultationID) @ Html.TextAreaFor (model= > model.ReplyContent, new {@ class = "form-control"}) @ Html.ValidationMessageFor (model= > model.ReplyContent)}}

Add a method to receive 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", "reply must be entered!") ; 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. Id parameter (RouteData.Values.ContainsKey ("id")) in the receive route

2. Find the CommonModel of the ID, get the ReplyContent passed by the client, set other parameters (ReplyTime,Status), and save it to the database

3. Return to the view

Delete comments

In the Consultation controller, add the Delete method

/ / delete comments / 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, add and delete js code / / delete function del () {var rows = $("# Consultation_List"). Datagrid ("getSelections"); if (! rows | | rows.length

< 1) { $.messager.alert("提示", "未选择任何行!"); return; } else if (rows.length >

0) {$.messager.confirmation ("confirm", "are you sure you want to delete the selected line?" , 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'); / / clear the selected line rows.length = 0; $("# Consultation_List"). Datagrid (' reload');}}); return } Thank you for your reading, the above is the content of "how to understand ASP.NET MVC5 website development management list, reply and delete". After the study of this article, I believe you have a deeper understanding of how to understand ASP.NET MVC5 website development management list, reply and delete, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report