【发布时间】:2011-05-05 01:50:15
【问题描述】:
我有一个包含 2 列的 mvc 3 表单。 The left column is a treeview and when a node is selected the div with id='partialView' is updated to show the details of that node.这似乎工作正常。 编辑表单(即部分视图)加载到 id='partialView' 的 div 中。
现在当用户提交此部分视图时会出现问题......现在它确实回发到控制器和正确的方法但是结果没有返回到 id='partialView' 的 div 而是发布到新页面.
所以这是我希望部分视图发布并返回替换现有部分视图的场景。
这可能吗?
我在下面包含我的代码以作为我的部分视图...
@model DataModel.Code
@using (Ajax.BeginForm("Edit", "Code", new AjaxOptions {
UpdateTargetId = "partialView",
HttpMethod="POST"
}
)) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Code</legend>
@Html.HiddenFor(model => model.CodeID)
<div class="editor-label">
@Html.LabelFor(model => model.Description)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Description)
@Html.ValidationMessageFor(model => model.Description)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Note)
@Html.ValidationMessageFor(model => model.Note)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.DateModified)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.DateModified)
@Html.ValidationMessageFor(model => model.DateModified)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.TopicID)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.TopicID)
@Html.ValidationMessageFor(model => model.TopicID)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Special)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Special)
@Html.ValidationMessageFor(model => model.Special)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Html)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Html)
@Html.ValidationMessageFor(model => model.Html)
</div>
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
}
<div>
@Html.ActionLink("Back to List", "Index")
</div>
@Html.Telerik().ScriptRegistrar().jQuery(true)
<script type="text/javascript">
$(document).ready(function () {
});
</script>
【问题讨论】:
-
您提交的操作是返回部分视图还是完整视图?编辑:我刚刚注意到您没有在局部视图中包含 jquery 脚本。尝试添加它们。
-
我返回一个 PartialView 但是它返回到一个新页面(不是 div partialView)。我已将脚本添加到页面中,它没有任何区别。事实上,脚本也在主页中。
标签: asp.net-mvc-3