Ajax.BeginForm 用法
例子:
@{ ViewBag.Title = "Home Page"; }
<!--需引入js文件--> <script src="http://966800.com/scripts/jquery.js"></script> <script src="http://966800.com/scripts/js/junobtrusiveam.js"></script> <div class="jumbotron"> <h1>ASP.NET</h1> <p class="lead">ASP.NET is a free web framework for building great Web sites and Web applications using HTML, CSS and JavaScript.</p> <p><a href="https://asp.net" class="btn btn-primary btn-lg">Learn more »</a></p> </div>
<!--使用--> <div class="row"> @using (Ajax.BeginForm("show", "home", new AjaxOptions { OnSuccess = "successg(data)", OnFailure = "failure(data)", LoadingElementId = "ajax-loader", //显示正在加载 UpdateTargetId = "list" //指向id=list })) { <input name="ttt" type="text" /> <input type="submit" value="提交" /> } <div id="list"></div> <div id="ajax-loader" style="width:285px;margin:auto;font-size: 18px;display:none;"> <img src="~/Content/5-121204193R5-50.gif" style="width:40px; " />数据正在加载,请稍后。。。 </div> </div> <script> function successg(data) { alert("成功"); } function failure(data) { alert("失败"); } </script>
控制器:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace WebApplication1.Controllers { public class HomeController : Controller { public ActionResult Index() { return View(); } public ActionResult Show(string ttt) { ViewBag.Message = ttt; return View(); } } }