在 ASP.NET MVC 3 应用程序中,我使用 Ajax.BeginForm 将书面文本发布到控制器。
@using (Ajax.BeginForm("Post", "Forum", new {threadId = Model.Thread.Id }, new AjaxOptions { OnSuccess = "PostReply" }))
{
<div id="reply-area">
<h3 style="border-bottom:1px solid black">POST REPLY</h3>
<span id="post-error" class="error-message"></span>
<textarea rows="1" cols="1" id="post-textarea" name="Content"> </textarea>
<input type="submit" class="button" value="Submit"/>
</div>
}
在控制器中我有
[HttpPost]
public ActionResult Post(int threadId,PostModel model)
{
bool Success = false;
if (ModelState.IsValid)
{
Success=Unit.ForumFacade.CreatePost(Unit.ForumFacade.GetThreadByID(threadId), model.Content, CurrentUserId);
if (Success == true) return View("PostSuccess");
}
return Json("fsdfds");
}
在 javascript 中我有这个
function PostReply(isRequestSuccessed) {
alert("asdasd");
if (isRequestSuccessed==false) {
$("#post-error").html("Please Try Again");
}
else
{
$("#post-error").html("");
}
}
问题是 Javascript 函数没有触发,而是警告,我的浏览器(Firefox)返回弹出窗口以下载 application/json 文件。
这里有什么问题吗?
确保您已将以下脚本添加到您的页面中:
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
并且您已在 web.config 中启用了不显眼的 javascript:
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
这就是使Ajax.*
帮助者如Ajax.BeginForm
上班。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)