asp.net MVC5 website Develop my consulting list and add a consultation (12) _ Practical Tips

Source: Internet
Author: User

The structure of the consultation last time, now two times to complete the consultation: 1, the user section, 2 Management section. This implementation of the user section, contains two features to view my consulting and consulting.

A, Menu

Open the last Consultationcontroller controller you added, add the menu action, and return to the distribution view

<summary>
  ///Menu
  ///</summary>
  ///<returns></returns>
  Public ActionResult Menu ()
  {return
   partialview ();
  }

Right-click to add View

<div class= "Easyui-accordion" >
  <div title= "Advisory management >
    <ul id=" Navmenu "class=" Nav nav-pills Nav-stacked ">
      <li> <a href=" javascript:void () "data-options=" ' Icons ': ' Icon-folder-page ', ' title ': ' Consulting management ', ' href ': ' @Url. Action ("Managelist", "consultation") ' "><span class=" Glyphicon glyphicon-list "> Consulting Management </span></a></li>
      <li> <a href= "javascript:void ()" data-options= "' Icons ': ' Icon-folder-user ', ' title ': ' My advice ', ' href ': ' @Url. Action ("MyList", "consultation") ' ><span class= ' Glyphicon Glyphicon-list-alt "> My consulting </span></a></li>
    </ul>
  </div>
</div >

Open Home/menu View again

Add a Distribution View reference

Run it, and look at the/member/home in the answering machine. Effects such as.

Second, my consultation

My Consulting section uses a DataGrid to display a list of my inquiries, and the DataGrid uses the Detailed View feature, which opens up and collapses to see the details.

The effect is this, when folded:

After the point is opened

This is the expansion of the DataGrid, first go to the official website to download Jquery-easyui-datagridview.zip, and then put the Jquery.easyui.datagrid.detailview.js file inside the project/ The Scripts folder.

Open the Consultationcontroller controller, add the Myjsonlist method, and return to my consulted JSON list

Public Jsonresult myjsonlist (int pageIndex = 1, int pageSize =)
  {
   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

<summary>
  ///My consulting
  ///</summary>
  ///<returns></returns>
  Public ActionResult MyList ()
  {return
   View ();
  }

Right-click to add a view for mylist.

@{Viewbag.title = "My Advice";} &lt;div id= "Toolbar" &gt; &lt;div&gt; &lt;a href= "#" id= "Btn_add" class= "Easyui-linkbutton" data-options= "iconcls": ' Icon-add ', Plain:true &gt; Consulting &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, singleselect:true, url: ' @Url. Action ("Myjsonlist", "consultation") ', columns: [[{field: ' ModelID ', title: ' ID '}, {field: ' title ', Title: ' Caption '}, {field: ' Inputer ', title: ' Consulting Person ', align: ' right '}, { Field: ' 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= ' padding:5px 0 ' &gt;&lt;/div&gt; ';
   }, 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);
   }
   });
  $ (' #Consultation_List '). DataGrid (' Fixdetailrowheight ', index);

 }
 }); Add button $ ("#btn_add"). Click (function () {Window.parent.addTab (for consultation), @Url. Action ("Add", "consultation") ","
 Icon-page ");
});
 &lt;/script&gt;

This code is longer and explains:

<div id= "Toolbar" >
 <div>
  <a href= "#" id= "Btn_add" class= "Easyui-linkbutton" data-options= " Iconcls: ' Icon-add ', plain:true ' > Consultation </a>
  <a href= "#" class= "Easyui-linkbutton" data-options= " Iconcls: ' Icon-reload ', plain:true "onclick=" $ (' #Consultation_List '). DataGrid (' reload '); > Refresh </a>
 </div>
</div>

<table id= "Consultation_list" ></table>

This is the subject and toolbar of the DataGrid.

The reference ~/scripts/common.js is because it contains a date formatting method, and the date that JSON passes must be formatted before it can be displayed properly.

Reference ~/scripts/jquery.easyui.datagrid.detailview.js is a DataGrid like a view must be.

This is the initialization DataGrid. 1 of them use the Jsondateformater method in Common.js to format the date. 2, is the Detailed view section

View:detailview,
Detailformatter:function (RowIndex, RowData) {return ' <div class= "detail" style= "" padding:5px 0 "></div>";}

These two sentences use the Detailed view and add a <DIV> for the detailed view

Onexpandrow:function (index, row) { 
   var detail = $ (this). The 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 a div with detailed views when the row is expanded

Here's how to add consultation/index this distribution view

Add the 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 enhanced type (consultation) Distribution view

@model Ninesky.Models.Consultation &lt;table style= "width:100%" &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; &lt;tr&gt; &lt;td colspan= "4" &gt; @if (model.replytime!= null) {&LT;SPAN&G
   t; admin in: @Model. Replytime reply as follows &lt;/span&gt; &lt;p style= "margin-top:8px" &gt;  @Model. Replycontent &lt;/p&gt;} &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt;
 

Completed

Third, the consultation

Add an Add action on the consultation controller

<summary>
  ///Add
  ///</summary>
  ///<returns></returns>
  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 user information first in action, construct a Commonmodel and pass to view

Right-click to add a view

@model Ninesky.Models.CommonModel @{viewbag.title = "conduct consultation";} @using (Html.BeginForm ()) {@Html. AntiForgeryToken () &lt;h4&gt; consulting &lt;/h4&gt; &lt;hr/&gt; &lt;div class= "Form-horizo Ntal "&gt; @Html. ValidationSummary (True) &lt;div class=" Form-group "&gt; &lt;label class =" Control-label col-sm-2 " &gt; Type &lt;/label&gt; &lt;div class= "col-sm-10" &gt; &lt;input id= "CategoryID" name= CategoryID "data-options=" URL: ' @ Url.action ("Jsoncombobox", "Category", new {model = "consultation"}) ', Valuefield: ' CategoryID ', TextField: ' Name ' class= "Easyui-combobox" style= "HEIGHT:34PX; width:280px "/&gt; @Html. Validationmessagefor (model =&gt; model. CategoryID) &lt;/div&gt; &lt;/div&gt; &lt;div class= "Form-group" &gt; @Html. Labelfor (model =&gt; model. Title, new {@class = "Control-label col-sm-2"}) &lt;div class= "col-sm-10" &gt; @Html. Textboxfor (model =&gt; model. Title, new {@class = "Form-control"}) @Html. validationmessagefor (model =&gt; model. Title) &lt;/div&gt; &lt;/div&gt; &lt;div class= "Form-group" &gt; @Html. Labelfor (model =&gt; model. Consultation.name, new {@class = "Control-label col-sm-2"}) &lt;div class= "col-sm-10" &gt; @Html. Textboxfor (model =&gt; model. Consultation.name, new {@class = "Form-control", @readonly = "ReadOnly"}) @Html. validationmessagefor (Model =&gt; MoD El. Consultation.name) &lt;/div&gt; &lt;/div&gt; &lt;div class= "Form-group" &gt; @Html. Labelfor (model =&gt; model. Consultation.qq, new {@class = "Control-label col-sm-2"}) &lt;div class= "col-sm-10" &gt; @Html. Textboxfor (Model =& Gt Model. Consultation.qq, new {@class = "Form-control"}) @Html. validationmessagefor (model =&gt; model. CONSULTATION.QQ) &lt;/div&gt; &lt;/div&gt; &lt;div class= "Form-group" &gt; @Html. Labelfor (model =&gt; model. Consultation.ispublic, new {@class = "Control-label col-sm-2"}) &lt;div class= "col-sm-10" &gt; @Html. Radiobuttonfo R (model =&gt; model. consultation.ispublic,true) Public @Html. Radiobuttonfor (model =&gt; model. Consultation.ispublic, False) view only @Html. validationmessagefor (model =&gt; model. Consultation.ispublic) &lt;/div&gt; &lt;/div&gt; &lt;div class= "Form-group" &gt; @Html. Labelfor (Model =&gt; mode L.consultation.email, new {@class = "Control-label col-sm-2"}) &lt;div class= "col-sm-10" &gt; @Html. Textboxfor (mod El =&gt; model. Consultation.email, new {@class = "Form-control"}) @Html. validationmessagefor (model =&gt; model. Consultation.email) &lt;/div&gt; &lt;/div&gt; &lt;div class= "Form-group" &gt; @Html labelfor (Model =&gt; MODEL.C Onsultation. Content, new {@class = "Control-label col-sm-2"}) &lt;div class= "col-sm-10" &gt; @Html. Textareafor (Model =&gt; MoD El. Consultation.content, new {@class = "Form-control"}) @Html. validationmessagefor (model =&gt; model. consultation.content) &lt;/div&gt; &lt;/div&gt; &lt;div class= "Form-group" &gt; &lt;div class= "Col-sm-offset-2 C Ol-sm-10 "&gt; &lt;input type="Submit" value= "submitted" class= "Btn btn-default"/&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt;}
 

Very similar to adding articles, write acceptance methods below

Add the Add action to the controller again

 [HttpPost] [Validateantiforgerytoken] public actionresult Add (Commonmodel commonMod
    EL) {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); }

In action if the validation passes, first find the user, and the article, attachment set to NULL, which is to prevent the user secretly entrainment Sihuo. Then initialize the Commonmodel hits, Inputer, and other fields and save them.

Effect:

My consulting implements two features for viewing my consulting and consulting, looking at the detailed view using a DataGrid.

The above is my consulting list and the implementation of the whole process of adding a consultation, I hope to help you learn.

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.