当前位置: 动力学知识库 > 问答 > 编程问答 >

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"]%>
分享给朋友:
您可能感兴趣的文章:
随机阅读: