In an ASP.NET MVC 3 application, I use Ajax.BeginForm to send a text message to the 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> }
In the controller I have
[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"); }
And in javascript I have this
function PostReply(isRequestSuccessed) { alert("asdasd"); if (isRequestSuccessed==false) { $("#post-error").html("Please Try Again"); } else { $("#post-error").html(""); } }
The problem is that the Javascript function does not work and does not cause a warning, my browser (Firefox) returns me a pop-up window for downloading the application / json file. What is wrong here?
source share