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 develop my consultation list and add consultation on ASP.NET MVC5 website

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

Share

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

This article mainly explains "how to achieve ASP.NET MVC5 website development my consultation list and add consultation", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's train of thought slowly in depth, together to study and learn "how to achieve ASP.NET MVC5 website development my consultation list and add consultation" bar!

I. menu

Open the added ConsultationController controller, add Menu action, and return to the distribution view

/ menu / public ActionResult Menu () {return PartialView ();}

Right-click to add view

Consulting management my consulting

Open the Home/menu view again

Add a distribution view reference

Run it and take a look at / Member/Home in the messenger. The effect is like.

Second, my consultation

My consultation section uses datagrid to display its own consultation list. Datagrid uses the detail view function, and you can see the details by clicking open and collapse.

The effect is this: when you fold:

After clicking on

This is an extension of datagrid, first go to the official website to download jquery-easyui-datagridview.zip, and then put the jquery.easyui.datagrid.detailview.js file in the project / Scripts folder.

Open the ConsultationController controller, add the MyJsonList method, and return the json list of my consultation

Public JsonResult MyJsonList (int pageIndex = 1, int pageSize = 20) {int _ total Var _ list = commonModelService.FindPageList (out _ total, pageIndex, pageSize, "Consultation", string.Empty, 0, User.Identity.Name, 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 ());}

Add the MyList method again and return directly to the view

/ my consultation / public ActionResult MyList () {return View ();}

Right-click to add a view for MyList.

@ {ViewBag.Title = "my consultation";} to refresh the consultation

This is the theme and toolbar of datagrid.

The reference to ~ / Scripts/Common.js is because it contains a date formatting method, and the date sent by json must be formatted before it can be displayed properly.

Referencing ~ / Scripts/jquery.easyui.datagrid.detailview.js is required for datagrid like views.

This is the initialization datagrid. Where 1 is to format the date using the jsonDateFormater method in Common.js. 2. It is the detailed view part.

View: detailview

DetailFormatter: function (rowIndex, rowData) {return';}

These two sentences use the detail view and add a

OnExpandRow: function (index, row) {var detail = $(this) .datagrid ('getRowDetail', index). Find (' div.detail'); detail.panel ({height: 160, border: false, cache: false, href:'@ Url.Content ("~ / Member/Consultation/Index") /'+ row.ModelID, onLoad: function () {$('# Consultation_List'). Datagrid ('fixDetailRowHeight', index);}})

This section is linked to the ~ / Member/Consultation/Index/id view for the div of the detail view when the row is expanded

Let's add the distributed view of Consultation/Index

Add Index action to the controller and return to the distribution view

Public ActionResult Index (int id) {return PartialView (commonModelService.Find (id) .consultation);}

Right-click to add reinforcement type (Consultation) distribution view

@ model Ninesky.Models.Consultation @ 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

}

Finish the job

Third, conduct consultation

Add Add action to the Consultation controller

/ / add / public ActionResult Add () {InterfaceUserService _ userService = new UserService (); var _ user = _ userService.Find (User.Identity.Name); CommonModel _ cModel = new CommonModel (); _ cModel.Consultation = new Consultation () {Email = _ user.Email, IsPublic = true, Name = _ user.DisplayName}; _ user = null; _ userService = null; return View (_ cModel);}

Query the user information in action, construct a CommonModel and pass it to the view

Right-click to add view

@ model Ninesky.Models.CommonModel@ {ViewBag.Title = "consult" } @ using (Html.BeginForm ()) {@ Html.AntiForgeryToken () consult @ Html.ValidationSummary (true) type @ Html.ValidationMessageFor (model = > model.CategoryID) @ Html.LabelFor (model = > model.Title, new {@ class = "control-label col-sm-2"}) @ Html.TextBoxFor (model = > model.Title) New {@ class = "form-control"}) @ Html.ValidationMessageFor (model = > model.Title) @ Html.LabelFor (model = > model.Consultation.Name, new {@ class = "control-label col-sm-2"}) @ Html.TextBoxFor (model = > model.Consultation.Name, new {@ class = "form-control") @ readonly = "readonly"}) @ Html.ValidationMessageFor (model = > model.Consultation.Name) @ Html.LabelFor (model = > model.Consultation.QQ, new {@ class = "control-label col-sm-2"}) @ Html.TextBoxFor (model = > model.Consultation.QQ, new {@ class = "form-control"}) @ Html.ValidationMessageFor (model = > model.Consultation.QQ) @ Html.LabelFor (model = > model.Consultation.IsPublic New {@ class = "control-label col-sm-2"}) @ Html.RadioButtonFor (model = > model.Consultation.IsPublic,true) Public @ Html.RadioButtonFor (model = > model.Consultation.IsPublic, false) only view @ Html.ValidationMessageFor (model = > model.Consultation.IsPublic) @ Html.LabelFor (model = > model.Consultation.Email) New {@ class = "control-label col-sm-2"}) @ Html.TextBoxFor (model = > model.Consultation.Email, new {@ class = "form-control"}) @ Html.ValidationMessageFor (model = > model.Consultation.Email) @ Html.LabelFor (model = > model.Consultation.Content, new {@ class = "control-label col-sm-2"}) @ Html.TextAreaFor (model = > model.Consultation.Content New {@ class = "form-control"}) @ Html.ValidationMessageFor (model = > model.Consultation.Content)}

Very similar to adding an article, write the acceptance method below

Add Add action to the controller again

[HttpPost] [ValidateAntiForgeryToken] public ActionResult Add (CommonModel commonModel) {if (ModelState.IsValid) {InterfaceUserService _ userService = new UserService (); var _ user = _ userService.Find (User.Identity.Name); if (commonModel.Article! = null) commonModel.Article = null; if (commonModel.Attachment! = null) commonModel.Attachment = null; if (commonModel.DefaultPicUrl! = null) commonModel.DefaultPicUrl = null; commonModel.Hits = 0; commonModel.Inputer = User.Identity.Name CommonModel.Model = "Consultation"; commonModel.ReleaseDate = System.DateTime.Now; commonModel.Status = 20; commonModel.Consultation.Name = _ user.DisplayName; _ user = null; _ userService = null; commonModel = commonModelService.Add (commonModel); if (commonModel.ModelID > 0) return View ("AddSucess", commonModel);} return View (commonModel);}

If the verification is passed in action, first find the user, and set Article and Attachment to null, which is to prevent users from secretly carrying private goods. Then initialize the Hits, Inputer, and other fields of commonModel and save them.

Effect:

My consulting implements the functions of viewing my consulting and consulting, and viewing a detailed view of the use of datagrid.

Thank you for your reading, the above is "how to achieve ASP.NET MVC5 website development of my consultation list and add consultation" content, after the study of this article, I believe you on how to achieve ASP.NET MVC5 website development of my consultation list and add consultation this question has a deeper experience, the specific use of the need for you to practice and verify. 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