[英]How to open a popup window in web forms without ajax modelpopupextender
[英]ajax forms and results in popup window
我在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>
這是我的控制器的操作:
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"
});
}
我希望用戶單擊“發布”按鈕,然后顯示彈出窗口,該窗口將在其中寫入Message
文本。
你能幫我(一些代碼)嗎?
謝謝。
您可以在AJAX選項中訂閱OnSuccess
javascript事件,然后以自己喜歡的方式顯示JSON結果(新窗口,div,...):
<% using (Ajax.BeginForm(
"DoComment",
"Publication",
new { id = Model.Publication.OID, parentId = Model.OID },
new AjaxOptions { OnSuccess = "onSuccess" })
) %>
然后定義onSuccess
javascript函數。 根據您使用的是jQuery還是MicrosoftAjax,此功能的實現可能會略有不同,尤其是檢索JSON結果的方式。
例如,如果您使用的是MicrosoftAjax(現已過時):
var onSuccess = function(e) {
var json = e.get_response().get_object();
alert(json.Message);
};
如果您是jQuery:
var onSuccess = function(json) {
alert(json.Message);
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.