62,046
社区成员
发帖
与我相关
我的任务
分享
@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" });
}
}
$("form").submit(function () {
AJAX操作...
return false;
});
@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>
}