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";} <div id= "Toolbar" > <div> <a href= "#" id= "Btn_add" class= "Easyui-linkbutton" data-options= "iconcls": ' Icon-add ', Plain:true > Consulting </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> <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: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 ' <div class= ' detail ' style= ' padding:5px 0 ' ></div> ';
}, 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 ");
});
</script>
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 <table style= "width:100%" > <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> <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> <tr> <th> @Html. Displaynamefor (model => model. Content) </th> <td colspan= "3" > @Html. Displayfor (model => model. Content) </td> </tr> <tr> <td colspan= "4" > @if (model.replytime!= null) {<SPAN&G
t; admin in: @Model. Replytime reply as follows </span> <p style= "margin-top:8px" > @Model. Replycontent </p>} </td> </tr> </table>
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 () <h4> consulting </h4> <hr/> <div class= "Form-horizo Ntal "> @Html. ValidationSummary (True) <div class=" Form-group "> <label class =" Control-label col-sm-2 " > Type </label> <div class= "col-sm-10" > <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 "/> @Html. Validationmessagefor (model => model. CategoryID) </div> </div> <div class= "Form-group" > @Html. Labelfor (model => model. Title, new {@class = "Control-label col-sm-2"}) <div class= "col-sm-10" > @Html. Textboxfor (model => model. Title, new {@class = "Form-control"}) @Html. validationmessagefor (model => model. Title) </div> </div> <div class= "Form-group" > @Html. Labelfor (model => model. Consultation.name, new {@class = "Control-label col-sm-2"}) <div class= "col-sm-10" > @Html. Textboxfor (model => model. Consultation.name, new {@class = "Form-control", @readonly = "ReadOnly"}) @Html. validationmessagefor (Model => MoD El. Consultation.name) </div> </div> <div class= "Form-group" > @Html. Labelfor (model => model. Consultation.qq, new {@class = "Control-label col-sm-2"}) <div class= "col-sm-10" > @Html. Textboxfor (Model =& Gt Model. Consultation.qq, new {@class = "Form-control"}) @Html. validationmessagefor (model => model. CONSULTATION.QQ) </div> </div> <div class= "Form-group" > @Html. Labelfor (model => model. Consultation.ispublic, new {@class = "Control-label col-sm-2"}) <div class= "col-sm-10" > @Html. Radiobuttonfo R (model => model. consultation.ispublic,true) Public @Html. Radiobuttonfor (model => model. Consultation.ispublic, False) view only @Html. validationmessagefor (model => model. Consultation.ispublic) </div> </div> <div class= "Form-group" > @Html. Labelfor (Model => mode L.consultation.email, new {@class = "Control-label col-sm-2"}) <div class= "col-sm-10" > @Html. Textboxfor (mod El => model. Consultation.email, new {@class = "Form-control"}) @Html. validationmessagefor (model => model. Consultation.email) </div> </div> <div class= "Form-group" > @Html labelfor (Model => MODEL.C Onsultation. Content, new {@class = "Control-label col-sm-2"}) <div class= "col-sm-10" > @Html. Textareafor (Model => MoD El. Consultation.content, new {@class = "Form-control"}) @Html. validationmessagefor (model => model. consultation.content) </div> </div> <div class= "Form-group" > <div class= "Col-sm-offset-2 C Ol-sm-10 "> <input type="Submit" value= "submitted" class= "Btn btn-default"/> </div> </div> </div>}
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.