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";} <div id= "Toolbar" > <div> <a href= "#" class= "Easyui-linkbutton" data-options= "iconcls: ' Icon-remove ', Plain:true "onclick=" del () "> Delete </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, 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 ' <div class= ' detail ' style= ' width:100%,p adding:5px 0 "></div>";
}, Onexpandrow:function (index, row) {var detail = $ (this). DataGrid (' Getrowdetail ', index). Find (' Div.detail '); $ (detail). html ("<iframe frameborder= ' 0 ' marginwidth= ' 0 ' height= ' 160px ' width= ' 100% ' src= '" @Url. Action ("Reply", " Consultation ")/" + row.
ModelID + "' ></iframe>");
$ (' #Consultation_List '). DataGrid (' Fixdetailrowheight ', index);
}
}); </script>
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 () <table style= "width:100%; font-size:12px; " > <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> @if (model.replytime!= null) {<tr> <TD colspan= "4" > <span> admin: @Model. replytime reply as follows </span> <br/> <p style= "margin-top:8px" > @Model. Re Plycontent </p> </td> </tr>} else {<tr> <th> reply @Html. Hidde Nfor (model => model. Consultationid) @Html. Validationmessagefor (Model=>model. Consultationid) </th> <td colspan= "3" > @Html. Textareafor (model => model. Replycontent, new {@class = "Form-control"}) @Html. Validationmessagefor (Model=>model.
replycontent) </td> </tr> <tr> <th> </th> <td colspan= "3" > <input type= "Submit" class= "btn_reply btn btn-primary" value= "OK"/> </td> </tr>} </table
>}
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
<summary>///Delete comments///</summary>///<param name= "IDs" > Public models id</param>///<returns
></returns> 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 < 1) {$.messager.alert ("hint", "No row selected!");
Return else if (Rows.length > 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.