当我进行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>
最佳答案
尝试删除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