<script> var url; //添加用户窗体 function newUser() { $('#dlg').dialog('open').dialog('setTitle', '学生信息添加'); $('#fm').form('clear'); url = '/Students/Add'; } //编辑 function editUser() { var row = $('#dg').datagrid('getSelected'); if (row) { $('#dlg').dialog('open').dialog('setTitle', '修改学生信息'); $('#fm').form('load', row); url = '/Students/Edit/' + row.StuId; } } //提交方法 function saveUser() { $('#fm').form('submit', { url: url, onSubmit: function () { return $(this).form('validate'); }, success: function (data) { if (data.Result==false) { $.messager.show({ title: 'Error', msg: data.Message }); } else { $('#dlg').dialog('close'); // close the dialog $('#dg').datagrid('reload'); // reload the user data } } }); } function InitGrid() { $("#dg").datagrid({ url: '/Students/StudentRead', title: '学生列表', toolbar: '#toolbar', rownumbers: true, fitcolumns: true, singleselect: true }); } </script> <table id="dg" title="My Users" class="easyui-datagrid" style="width:550px;height:250px" url="/Students/StudentRead" toolbar="#toolbar" rownumbers="true" fitcolumns="true" singleselect="true"> <thead> <tr> <th field="StuName" width="50">学生姓名</th> <th field="Age" width="50">年龄</th> <th field="Sex" width="50">性别</th> <th field="CreateTime" width="50">创建时间</th> </tr> </thead> </table> <div id="toolbar"> <a href="#" class="easyui-linkbutton" iconcls="icon-add" plain="true" onclick="newUser()">New User</a> <a href="#" class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="editUser()">Edit User</a> <a href="#" class="easyui-linkbutton" iconcls="icon-remove" plain="true" onclick="destroyUser()">Remove User</a> </div> <div id="dlg" class="easyui-dialog" style="width:400px;height:280px;padding:10px 20px" closed="true" buttons="#dlg-buttons"> <div class="ftitle">学生信息</div> <form id="fm" method="post"> <div class="fitem"> <label>StuName:</label> <input name="StuName" class="easyui-textbox"> </div> <div class="fitem"> <label>Age:</label> <input name="Age" class="easyui-textbox"> </div> <input type="hidden" name="StuId"/> </form> </div> <div id="dlg-buttons"> <a href="#" class="easyui-linkbutton" iconcls="icon-ok" onclick="saveUser()">Save</a> <a href="#" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">Cancel</a> </div>