【发布时间】:2012-02-13 13:09:43
【问题描述】:
我在局部视图中有一个 jquery 对话框:
@model JQueryDialogPoc.Models.FeedBack
@using (Ajax.BeginForm("GiveFeedback", "Home", null, new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "emailDialog" }, new { id = "popForm" }))
{
<div class="popUp">
<div>
<ul>
<li>
@Html.EditorFor(x => x.Feedback)
@Html.ValidationMessageFor(x => x.Feedback) </li>
</ul>
</div>
<input type="submit" />
</div>
}
型号是:
public class FeedBack
{
[Required]
[Display(Name = "Feedback")]
public string Feedback { get; set; }
}
我像这样渲染局部视图:
@Html.Partial("MyFeedbackPartialView");
我有这个 js 文件,我用它来打开对话框:
$("div.popUp").dialog({
title: "",
close: function () {
},
modal: true,
show: "fade",
hide: "fade",
open: function (event, ui) {
$(this).parent().appendTo($('#popForm'));
$(this).load(options.url, function() {
var $jQval = $.validator;
$jQval.unobtrusive.parse($(this));
});
}
});
the actionMethod is :
[HttpPost]
public ActionResult GiveFeedback(string Feedback)
{
return Json(new {result = "Back from Server!"});
}
现在的问题是每次我点击提交按钮时,它都会重定向页面并向我显示:
{"result":"Back from Server!"}
虽然它应该发出 ajax 请求!
知道为什么会这样吗?
【问题讨论】:
-
将方法的返回类型改为JsonReult或PartialViewResult,可能是这个原因。
标签: c# jquery asp.net-mvc jquery-ui