ASP.NET MVC ajax - 数据传输

时间:2010-03-23 19:04:13

标签: asp.net-mvc ajax

如何从行动中获得结果? 我需要在成功后在页面上显示 commentID (aspx) 评论插入。

控制器

[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

1 个答案:

答案 0 :(得分:0)

使用此:

ViewData["ID"] = commentID;

然后用:

打印出来
<%= ViewData["ID"]%>