日期:2014-05-17 浏览次数:20602 次
@model MvcWithAjax.Models.SoSoKe_Ad @{ ViewBag.Title = "Index"; } <script type="text/javascript" src="../../Scripts/jquery-1.6.2.js"></script> <h2>Index</h2> <script type="text/javascript"> $(function () { $("form").submit(function () { $.ajax({ url: $(this).attr("action"), type: "post", data: $(this).serialize(), success: function (data) { alert(data.msg); } }); }); }) </script> @using (Html.BeginForm()) { <fieldset> <legend>广告</legend> <div>编号:@Html.TextBoxFor(model => model.Ad_ID)</div> <div>信息:@Html.TextBoxFor(model => model.Ad_Info)</div> <div> <input type="submit" value="提交" /> </div> </fieldset> }
public class HomeController : Controller { // // GET: /Home/ public ActionResult Index() { return View(); } [HttpPost] public ActionResult Index(SoSoKe_Ad ad) { return Json(new { msg = "1" }); } }
@using (Ajax.BeginForm()) { <fieldset> <legend>广告</legend> <div>编号:@Html.TextBoxFor(model => model.Ad_ID)</div> <div>信息:@Html.TextBoxFor(model => model.Ad_Info)</div> <div> <input type="submit" value="提交" /> </div> </fieldset> }
------解决方案--------------------
$("form").submit(function () { AJAX操作... return false; });