0
我想从我的剃须刀视图提交一个ajax窗体,并且我希望控制器返回一个JSON对象。当我使用(“#form0”)。submit(alert(“hi”););数据发送到控制器,我收到警报。但是,当我使用(“#form0”)。submit(function(){alert(“hi”);});数据没有通过,我也没有收到警报。我觉得这是我的语法轻微,我错过了。下面是相关的代码:无法重载提交方法的Ajax.BeginForm
的jQuery:
$(function() {
//setting up the schedule modal dialoag.
$("#schedModal").dialog({
buttons: {
Submit:
function() {
$("#form0").ajaxSubmit(function() {
//this is where I want to put the magic, but I need the alert to fire first.
alert("hi");
return false;
});
},
Cancel:
function() {
$(this).dialog("close");
}
},
autoOpen: false,
minHeight: 350,
modal: true,
resizable: false
});
有针对性的观点:
@model FSDS.DataModels.Schedule
@using (Ajax.BeginForm("scheduleNew", null, new AjaxOptions { UpdateTargetId = "partial" }, new {}))
{
@Html.ValidationSummary(true)
<div class="editor-label">
@Html.LabelFor(model => model.ScheduleName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ScheduleName)
@Html.ValidationMessageFor(model => model.ScheduleName)
</div>
@* tons of other labels and editor fields go in here, omitted for brevity. *@
}
控制器,如果该事项:
[HttpPost]
public ActionResult scheduleNew(Schedule schedule)
{
if (Request.HttpMethod == "POST")
{
FSDSDBEntities context = new FSDSDBEntities();
if (ModelState.IsValid)
{
context.Schedules.AddObject(schedule);
context.SaveChanges();
}
return Json(schedule);
}
else
{
return PartialView();
}
}
工程就像一个梦。你是一个绅士和学者,Darin Dimitrov。 – Billdr 2012-08-06 17:05:53