弹出窗口中的ajax表单和结果
我在弹出窗口中的ajax表单和结果,ajax,asp.net-mvc,Ajax,Asp.net Mvc,我在DoComment.ascx中有一个表单: <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<DT.KazBilet.Objects.PublicationComment>" %> <div class="wrap"> <h4>Comment</h4> <%using (Ajax.BeginForm("DoComment", "
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>
我希望用户单击“发布”按钮,然后显示弹出窗口,其中将写入来自消息的文本
你能帮我(一些代码)吗
谢谢。您可以在AJAX选项中订阅OnSuccess
javascript事件,然后以您喜欢的方式显示检索到的JSON结果(新窗口、div等):
如果您是jQuery:
var onSuccess = function(json) {
alert(json.Message);
};
@user348173,也许你有javascript错误?可能您没有将jquery.unobtrusive ajax.js
脚本包括到页面中(如果您使用jquery)或MicrosoftMvcAjax.js
脚本?我需要这些脚本来调整表单。也许你的代码还有其他问题?这是不可能的,因为你还没有展示你的代码。您可以使用FireBug调试javascript。
<% using (Ajax.BeginForm(
"DoComment",
"Publication",
new { id = Model.Publication.OID, parentId = Model.OID },
new AjaxOptions { OnSuccess = "onSuccess" })
) %>
var onSuccess = function(e) {
var json = e.get_response().get_object();
alert(json.Message);
};
var onSuccess = function(json) {
alert(json.Message);
};