MVC jQueryAjax异步实现增删改查和分页.docx

上传人:b****8 文档编号:9643175 上传时间:2023-05-20 格式:DOCX 页数:30 大小:19.46KB
下载 相关 举报
MVC jQueryAjax异步实现增删改查和分页.docx_第1页
第1页 / 共30页
MVC jQueryAjax异步实现增删改查和分页.docx_第2页
第2页 / 共30页
MVC jQueryAjax异步实现增删改查和分页.docx_第3页
第3页 / 共30页
MVC jQueryAjax异步实现增删改查和分页.docx_第4页
第4页 / 共30页
MVC jQueryAjax异步实现增删改查和分页.docx_第5页
第5页 / 共30页
MVC jQueryAjax异步实现增删改查和分页.docx_第6页
第6页 / 共30页
MVC jQueryAjax异步实现增删改查和分页.docx_第7页
第7页 / 共30页
MVC jQueryAjax异步实现增删改查和分页.docx_第8页
第8页 / 共30页
MVC jQueryAjax异步实现增删改查和分页.docx_第9页
第9页 / 共30页
MVC jQueryAjax异步实现增删改查和分页.docx_第10页
第10页 / 共30页
MVC jQueryAjax异步实现增删改查和分页.docx_第11页
第11页 / 共30页
MVC jQueryAjax异步实现增删改查和分页.docx_第12页
第12页 / 共30页
MVC jQueryAjax异步实现增删改查和分页.docx_第13页
第13页 / 共30页
MVC jQueryAjax异步实现增删改查和分页.docx_第14页
第14页 / 共30页
MVC jQueryAjax异步实现增删改查和分页.docx_第15页
第15页 / 共30页
MVC jQueryAjax异步实现增删改查和分页.docx_第16页
第16页 / 共30页
MVC jQueryAjax异步实现增删改查和分页.docx_第17页
第17页 / 共30页
MVC jQueryAjax异步实现增删改查和分页.docx_第18页
第18页 / 共30页
MVC jQueryAjax异步实现增删改查和分页.docx_第19页
第19页 / 共30页
MVC jQueryAjax异步实现增删改查和分页.docx_第20页
第20页 / 共30页
亲,该文档总共30页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

MVC jQueryAjax异步实现增删改查和分页.docx

《MVC jQueryAjax异步实现增删改查和分页.docx》由会员分享,可在线阅读,更多相关《MVC jQueryAjax异步实现增删改查和分页.docx(30页珍藏版)》请在冰点文库上搜索。

MVC jQueryAjax异步实现增删改查和分页.docx

MVCjQueryAjax异步实现增删改查和分页

  这篇文章主要为大家详细介绍了MVC结合jQuery.Ajax异步实现增删改查和分页的相关资料,感兴趣的小伙伴们可以参考一下

  本文实例为大家分享了MVC+jQuery.Ajax异步实现增删改查和分页的具体代码,供大家参考,具体内容如下

  1、Model层代码

  usingSystem;

  usingSystem.Data;

  usingSystem.Configuration;

  usingSystem.Linq;

  usingSystem.Web;

  usingSystem.Web.Security;

  usingSystem.Web.UI;

  usingSystem.Web.UI.HtmlControls;

  usingSystem.Web.UI.WebControls;

  usingSystem.Web.UI.WebControls.WebParts;

  usingSystem.Xml.Linq;

  usingSystem.Collections.Generic;

  usingMvcExamples;

  usingSystem.Web.Mvc;

  namespaceMvcExamples.Web.Models

  {

   publicclassStudentModels

   {

   ///<summary>

   ///获取学生信息列表

   ///</summary>

   publicList<MvcExamples.Model.Student>StudentList{get;set;}

   ///<summary>

   ///获取教工信息列表

   ///</summary>

   publicList<MvcExamples.Model.Teacher>TeacherList{get;set;}

   ///<summary>

   ///获取学生信息列表(分页)

   ///</summary>

   publicPagedList<MvcExamples.Model.Student>GetStudentList{get;set;}

   }

  }

  2、View层代码

  <%@PageTitle=""Language="C#"MasterPageFile="~/Views/Shared/Site.Master"Inherits="System.Web.Mvc.ViewPage<MvcExamples.Web.Models.StudentModels>"%>

  <asp:

ContentID="Content1"ContentPlaceHolderID="TitleContent"runat="server">

   Index

  </asp:

Content>

  <asp:

ContentID="Content3"ContentPlaceHolderID="HeadContent"runat="server">

   <scriptsrc="type="text/javascript"></script>

   <scriptsrc="type="text/javascript"></script>

   <scriptsrc="type="text/javascript"></script>

   <linkhref="rel="stylesheet"type="text/css"/>

   <scripttype="text/javascript">

   $(function(){

   //添加学生信息

   $('#a_add').click(function(){

    $('#window').dialog({ 

     title:

"添加学生信息",

     width:

300,

     height:

200,

     modal:

true,

     buttons:

     "取消":

function(){

      $(this).dialog("close");//当点击取消按钮时,关闭窗口

     }, 

     "添加":

function(){ 

      //当点击添加按钮时,获取各参数的值

      varsno=$('#sno').val();

      varsname=$('#sname').val();

      varssex=$('#ssex').val();

      varsbirsthday=$('#sbirthday').val();

      varsclass=$('#sclass').val();

      $.ajax({

      type:

'post',

      url:

'/Student/AddStudent',//路径为添加方法

      data:

'no='+sno+'&name='+sname+'&sex='+ssex+'&birsthday='+sbirsthday+'&sclass='+sclass,//参数的个数和名字要和方法的名字保持一致

      success:

function(json)//返回的是Json类型的

      {

       $('#window').dialog("close"); 

       //判断是否成功

       if(json.result=="true")

       {

       $('#btn_close').click();

       alert('恭喜你,修改成功!

'); 

       }else{

       alert('抱歉,修改失败!

');

       }

      }

      });

     }

     } 

    });

   })

   //删除学生信息

   $('.a_delete').click(function(){

    //确认是否删除

    if(confirm("是否删除此条信息?

"))

    {

    $.ajax({

     type:

'post',

     url:

'/Student/DeleteStudent',

     data:

'no='+$(this).attr("sno"),//获取当前对象的属性(自定义属性)sno的值,用自定义属性保存相应需要的数据

     sucess:

function(json)

     {

      if(json.result=="true")

      {

      alert("恭喜你,已成功删除!

");

      }else

      {

      alert("抱歉,删除失败!

");

      }

     }

    })

    }

   })

   //修改学生信息

   $('.a_update').click(function(){

    varstudent=$(this);

    $("#sno").attr("value",student.attr("sno"));

    $("#sname").attr("value",student.attr("sname"));

    $("#ssex").attr("value",student.attr("ssex"));

    $("#sbirthday").attr("value",student.attr("sbirthday"));

    $("#sclass").attr("value",student.attr("sclass"));

    $('#window').dialog({ 

    title:

"修改学生信息",

    width:

300,

    height:

200,

    modal:

true,

    buttons:

     "取消":

function(){

     $(this).dialog("close"); 

     }, 

     "修改":

function(){ 

     varsno=$('#sno').val();

     varsname=$('#sname').val();

     varssex=$('#ssex').val();

     varsbirsthday=$('#sbirthday').val();

     varsclass=$('#sclass').val();

     $.ajax({

     type:

'post',

     url:

'/Student/UpdateStudent',

     data:

'no='+sno+'&name='+sname+'&sex='+ssex+'&birsthday='+sbirsthday+'&sclass='+sclass,

     success:

function(json)

      {

      $('#window').dialog("close"); 

      if(json.result=="true")

      {

       $('#btn_close').click();

       alert('恭喜你,修改成功!

'); 

      }else{

       alert('抱歉,修改失败!

');

      }

      }

     });

     }

     } 

    }); 

   });

   })

   </script>

  </asp:

Content>

  <asp:

ContentID="Content2"ContentPlaceHolderID="MainContent"runat="server">

   <h2>

   MVC演示</h2>

   <table>

   <thead>

    <tr>

    <td>

     学生表

    </td>

    </tr>

    <tr>

    <td>

     学号

    </td>

    <td>

     姓名

    </td>

    <td>

     性别

    </td>

    <td>

     生日

    </td>

    <td>

     班级

    </td>

    <td>

     操作

    </td>

    </tr>

   </thead>

   <tbody>

    <%foreach(MvcExamples.Model.StudentstudentinModel.GetStudentList)

    {%>

    <tr>

    <td>

     <%=student.sno%>

    </td>

    <td>

     <%=student.sname%>

    </td>

    <td>

     <%=student.ssex%>

    </td>

    <td>

     <%=student.sbirthday%>

    </td>

    <td>

     <%=student.sclass%>

    </td>

    <td>

    <ahref="javascript:

void(0);"class="a_update"sno="<%=student.sno%>"sname="<%=student.sname%>"ssex="<%=student.ssex%>"

     sbirthday="<%=student.sbirthday%>"sclass="<%=student.sclass%>">修改</a>

       

     <ahref="javascript:

void(0);"class="a_delete"sno="<%=student.sno%>">删除</a>

    </td>

    </tr>

    <%}%>

   </tbody>

   <tfoot>

    <tr>

    <td>

     全选

    </td>

    <tdcolspan="5"style="text-align:

right;">

     <ahref="javascript:

void(0);"id="a_add">添加</a>

    </td>

    </tr>

   </tfoot>

   </table>

   <%=Html.MikePager(Model.GetStudentList)%>

   <br/>

   <table>

   <thead>

    <tr>

    <td>

     学生表

    </td>

    </tr>

    <tr>

    <td>

     学号

    </td>

    <td>

     姓名

    </td>

    <td>

     性别

    </td>

    <td>

     生

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 高中教育 > 小学教育

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2