ASP.NET MVC ajax - data transfer
How can I get result from action? I need to show the commentID on the page (aspx) after successes comment insert.
controller
[AcceptVerbs(HttpVerbs.Post )]
public ActionResult ShowArticleByAjax(Guid id, string commentBody)
{
Guid commentID = Comment.InsertComment(id, commentBody);
//How can I tranfer commentID to the aspx page ???
return PartialView("CommentDetails",Article.GetArticleByID(id));
}
ascx
<%using (Ajax.BeginForm("ShowArticleByAjax", new { id = Model.ID },
new AjaxOptions {
HttpMethod = "Post",
UpdateTargetId = "divCommentDetails",
OnSuccess = "successAddComment",
OnFailure = "failureAddComment",
OnBegin = "beginAddComment"
}))
{ %>
<p>
<%=Html.TextArea("commentBody", new { cols = "100%", rows = "10" })%>
</p>
<p>
开发者_如何转开发<input name="submit" type="image" src="../../Content/Images/Design/button_s.gif"
id="submit" />
</p>
<%} %>
aspx
doesn't matter
Use the this:
ViewData["ID"] = commentID;
and then print it with:
<%= ViewData["ID"]%>
精彩评论