【发布时间】:2013-05-23 18:53:25
【问题描述】:
在我的 ASP MVC3 视图中,我使用以下 Ajax 调用来检索局部视图并将该局部视图附加到特定的 fieldset
Ajax
$("#addItem").click(function () {
alert("here");
$.ajax({
url: '@Url.Action("BlankDropDownItem", "DropDownValues")',
dataType: 'html',
cache: false,
success: function (html) {
alert(html);
$("#items").append(html);
}
});
return false;
});
这个Ajax 调用了一个非常简单的ViewResult 控制器方法,它应该返回部分视图。
控制器
public ViewResult BlankDropDownItem()
{
return View("DropDownItemPartial", new DropDownValues());
}
这是部分中的所有代码。当我在 VS 2010 中创建它时(我现在已经这样做了两次以确保)我检查了“部分视图”复选框,它使“使用共享布局”选项变灰。
局部视图
@model Monet.Models.DropDownValues
<div class="editor-label">
@Html.LabelFor(model => model.AllowedValue)
</div>
<div class="label-field">
@Html.EditorFor(model => model.AllowedValue)
@Html.ValidationMessageFor(model => model.AllowedValue)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.DisplayValue)
</div>
<div class="label-field">
@Html.EditorFor(model => model.DisplayValue)
@Html.ValidationMessageFor(model => model.DisplayValue)
</div>
无论出于何种原因,当我在 Ajax success 函数的这一行返回的 html 对象上放置一个 alert 时
success: function (html) {
我看到html 对象从共享布局返回所有 HTML,因此它本质上是返回整个页面而不是部分视图。这是 Ajax 调用完成后的屏幕截图。
【问题讨论】:
标签: ajax asp.net-mvc asp.net-mvc-3 jquery partial-views