简体   繁体   English

Ajax表单和结果在弹出窗口中

[英]ajax forms and results in popup window

I have a form in DoComment.ascx : 我在DoComment.ascx有一个表格:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DT.KazBilet.Objects.PublicationComment>" %>
<div class="wrap">
    <h4>Comment</h4>
    <%using (Ajax.BeginForm("DoComment", "Publication", new {id = Model.Publication.OID, parentId = Model.OID},new AjaxOptions()))
      {%>    
    <%=Html.TextAreaFor(x=>x.Text) %>    
    <%-- <textarea style="width: 100%; height: 152px;"></textarea>--%>
    <input type="submit" value="Publish" class="btn ok_btn" />
    <%}%>
</div>

This is my controller's action: 这是我的控制器的操作:

public JsonResult DoComment(PublicationComment model, int id, int parentId)
        {
            PublicationRepository.SaveComment(User.Identity.Name,id, parentId, model.Text);

            return Json(new {
                 Message = "You comment on moderation"
                 });
        }

I want that user clicks on Publish button then show popup window where will be written text from Message . 我希望用户单击“发布”按钮,然后显示弹出窗口,该窗口将在其中写入Message文本。
Can you help me(some code)? 你能帮我(一些代码)吗?

Thanks. 谢谢。

You could subscribe to the OnSuccess javascript event in the AJAX options and then show the JSON result you have retrieved the way you like (new window, div, ...): 您可以在AJAX选项中订阅OnSuccess javascript事件,然后以自己喜欢的方式显示JSON结果(新窗口,div,...):

<% using (Ajax.BeginForm(
    "DoComment", 
    "Publication", 
    new { id = Model.Publication.OID, parentId = Model.OID },
    new AjaxOptions { OnSuccess = "onSuccess" })
) %>

and then you would define the onSuccess javascript function. 然后定义onSuccess javascript函数。 Depending on whether you use jQuery or MicrosoftAjax the implementation of this function might slightly vary and more specifically the way to retrieve the JSON result. 根据您使用的是jQuery还是MicrosoftAjax,此功能的实现可能会略有不同,尤其是检索JSON结果的方式。

For example if you are using MicrosoftAjax (obsolete now): 例如,如果您使用的是MicrosoftAjax(现已过时):

var onSuccess = function(e) {
    var json = e.get_response().get_object();    
    alert(json.Message);
};

and if you are jQuery: 如果您是jQuery:

var onSuccess = function(json) {
    alert(json.Message);
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM