首页 > Web开发 > 详细

MVC入门第一天

时间:2016-11-19 02:01:01      阅读:182      评论:0      收藏:0      [点我收藏+]

一、异步的两种方法

  1.  用jQ的异步  返回content
    1. controllor:return Content(sum.ToString());//这里涉及到一个自动封装的问题
    2. html页:<form id="form1">
                      <input type="text" name="calc1" />+
                      <input type="text" name="calc2" />
                      <input type="button" id="btnAdd" value="加" />
                      <input type="text" name="sum" id="sum" />
                  </form>
    3.  $(function () {
                  $(‘#btnAdd‘).click(function () {
                      $.post(
                          ‘@Url.Action("CalcAdd","Home")‘,//提交到的地址
                          $(‘#form1‘).serialize(),//把表单的数据序列化发送
                          function (msg) {//回调函数,msg是接收到的服务器端发来的数据
                              $(‘#sum‘).val(msg);
                          }
                          )
                  })
              })

     2.AjaxHelper类

  1. controller代码
    1. public ActionResult CalcAdd1(int calc1, int calc2)
    2. return Json(temp, JsonRequestBehavior.AllowGet);
  2. html代码
    1.  @using (Ajax.BeginForm("CalcAdd1", "home", new AjaxOptions()
              {
                  OnSuccess = "Success"
              }))
              {
                  <input type="text" name="calc1" />
                  <span>+</span>
                  <input type="text" name="calc2" />
                  <input type="submit" value="=" />
                  <input type="text" id="result" />
              }
  3. 调用的脚本
    1. <script src="~/jquery-1.8.3.min.js"></script>
          <script src="~/jquery.unobtrusive-ajax.min.js"></script>

 

MVC入门第一天

原文:http://www.cnblogs.com/pangzhixing/p/6079192.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!