Ajax.BeginForm不调用的onSuccess [英] Ajax.BeginForm doesn't call onSuccess
问题描述
在ASP.NET MVC 3应用程序我用Ajax.BeginForm后所著文字的控制器。
In ASP.NET MVC 3 application I use Ajax.BeginForm to post writed text to controller.
@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我有这
And in javascript I have this
function PostReply(isRequestSuccessed) {
alert("asdasd");
if (isRequestSuccessed==false) {
$("#post-error").html("Please Try Again");
}
else
{
$("#post-error").html("");
}
}
问题是,JavaScript的功能不发射和isntead警报,我的浏览器(Firefox)返回我弹出下载应用程序/ JSON文件。
什么是错在这里?
The problem is that Javascript's function doesn't firing and isntead the alert, my browser(Firefox) returns me pop-up to download application/json file. What is wrong here?
推荐答案
请确保您已下面的脚本到你的页面:
Make sure you have included the following script to your page:
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
和已启用不显眼的JavaScript在你的web.config:
and that you have enabled unobtrusive javascript in your web.config:
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
这是什么使阿贾克斯。*
助手,如 Ajax.BeginForm
工作
This is what makes Ajax.*
helpers such as Ajax.BeginForm
to work.
这篇关于Ajax.BeginForm不调用的onSuccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!