(On the basis of the last essay code)
1.datagrid Code:
<div style= "width:100%;height:100%;" >
<table class= "Easyui-datagrid" id= "Datagriduser" style= "width:100%; height:95%; "data-options=" Singleselect:true,url: ' @Url. Action ("GetList") ', Method: ' Get ',Toolbar:toolbar "Pagination= "true" Sortname= "Id" sortorder= "ASC" >
<thead>
<tr>
<th style= "width:10%" data-options= "field: ' Id '"Sortable= "true" > Numbering </th>
<th style= "width:15%" data-options= "field: ' Name '" sortable= "true" > Login </th>
<th style= "width:15%" data-options= "field: ' Realname '" sortable= "true" > Name </th>
<th style= "width:15%" data-options= "field: ' Sex '" sortable= "true" > Gender </th>
<th style= "width:15%" data-options= "field: ' Email '" > email </th>
<th style= "width:15%" data-options= "field: ' Phone '" > Phone </th>
<th style= "width:15%" data-options= "field: ' Address '" > Addresses </th>
</tr>
</thead>
</table>
</div>
2.JS Code
<script type= "Text/javascript" >
var toolbar = [{
Text: ' Delete user ',
Iconcls: ' Icon-clear ',
Handler:function () {
var row = $ ("#datagridUser"). DataGrid ("getselected");
if (row! = null) {
var userId = row. Id;
Perform a delete operation
if (Confirm ("Confirm delete?") "))
{
$.ajax ({
Type: "POST",
URL: "/usermanager/deleteuser",
Data: "id=" + userId,
Success:function (Result) {
if (result = = "true") {
$ ("#datagridUser"). DataGrid ("Reload");
}
}
});
}
}
else {
Alert ("Please select the item you want to delete!") ");
}
}
}, {
Text: ' View Details ',
Iconcls: ' Icon-search ',
Handler:function () {
var row = $ ("#datagridUser"). DataGrid ("getselected");
if (row! = null) {
Binding form data
var userId = row. Id;
Perform a query operation
$.ajax ({
Type: "Get",
URL: "/usermanager/getuser",
Data: "id=" + userId,
Success:function (Jsonuserinfo) {
var json = Json.parse (jsonuserinfo);
$ ("#textInfoName"). Val (JSON. Name);
$ ("#textInfoRealName"). Val (JSON. Realname);
$ ("#textInfoSex"). Val (JSON. SEX);
$ ("#textInfoEmail"). Val (JSON. Email);
$ ("#textInfoPhone"). Val (JSON. Phone);
$ ("#textInfoAddress"). Val (JSON. Address);
Open window, center display
$ (' #windowUserInfo '). Window ({
Top: ($ (window). Height ()-300) * 0.5,
Left: ($ (window). Width ()-500) * 0.5,
}). window (' open ');
}
});
}
else {
Alert ("Please select User!") ");
}
}
}];
</script>
Note: var row = $ ("#datagridUser"). The DataGrid ("getselected") gets the selected row; var userId = row. ID gets the ID of the row data; URL: "/usermanager/getuser" Ajax invokes action to get data; My action returns a JSON string;$ ("#textInfoName"). val (JSON. Name) to bind the display data .
3.control
[HttpPost]
Public ActionResult deleteuser (int id)
{
var user = Userservice.get (x = x.id = = Id); Gets the user to delete
if (userservice.delete (user))
{
Return Content ("true");
}
Else
{
Return Content ("false");
}
}
[HttpGet]
public string GetUser (int id)
{
var user = Userservice.get (x = x.id = = Id); Gets the user to delete
var json = jsonconvert.serializeobject (user);
return JSON;
}
Note: The code is only part, the memo is convenient to view later
Gets the data for the DataGrid selected row, displayed in the Windows window