当我进行ajax调用时,控制器正在重定向而不更新我的代码,我的代码如下所示。
这是在_layout.cshtml
中<code>
<script src="@Url.Content("~/Scripts/jquery-1.4.1.min.js")" type="text/javascript">
</script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/MicrosoftAjax.js")" type="text/javascript">
</script>
<script src="@Url.Content("~/Scripts/MicrosoftMvcAjax.js")" type="text/javascript">
</script>
</code>
这就是网络配置的样子,我也尝试过关闭不引人注目的javascript而没有运气。
<code>
<appSettings>
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
</code>
我的控制器方法如下所示
<code>
[HttpPost]
public ActionResult Create(lesson lesson)
{
if (ModelState.IsValid)
{
//Save Album
lesson.dateCreated = DateTime.Now;
lesson.dateSubmitted = DateTime.Now;
lesson.statusID = SUBMITTED;
lesson.submittedByUserID = getAppUserID();
lesson.prjLessonID = createLessonPrjID(lesson.projectID);
storeDB.lessons.InsertOnSubmit(lesson);
storeDB.SubmitChanges();
return RedirectToAction("Index");
}
// Invalid – redisplay with errors
else
return View(lesson);
}
</code>
有什么想法吗?提前谢谢。
<code>
@if (item.statusID != null)
{
<td id ="approvedmsg">@item.getLessonStatus(item.statusID.Value)</td>
}
else
{
<td> </td>
}
@if (item.statusID != 3)
{
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.lessonID }) |
@Ajax.ActionLink("Delete", "Delete", new { id = item.lessonID }, new AjaxOptions { UpdateTargetId = "approvedmsg"})
</td>
}
</code>
答案 0 :(得分:5)
尝试删除MicrosoftAjax.js
和MicrosoftMvcAjax.js
并仅使用
<script src="<%=Url.Content("~/Scripts/jquery-1.4.1.min.js")%>" type="text/javascript"></script>
<script src="<%=Url.Content("~/Scripts/jquery.validate.min.js")%>" type="text/javascript"></script>
<script src="<%=Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")%>" type="text/javascript"></script>
<script src="<%=Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")%>" type="text/javascript"></script>
关于它的好帖子http://yobriefcase.posterous.com/unobtrusive-javascript-in-mvc3