我目前正在左栏中显示树视图。 当用户选择一个节点时,我正在使用来自ajax调用的响应加载右列#details。这很好用。
我现在也希望通过ajax提交正确的列#details。我能够将帖子捕获回服务器但是当我将字符串返回到#details部分时,它正在加载整个页面,其中包含“已成功保存”字符串
我真的希望将“已成功保存”的字符串放在右列的div元素中。
这是一个ajax响应,再次做另一个ajax响应(我想返回第一个ajax响应)。
这可能吗?
我的编辑表单如下所示
@using (Ajax.BeginForm("Edit", new AjaxOptions { UpdateTargetId = "#results" })) {
@Html.ValidationSummary(true)
if (Model != null) {
<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-label">
@Html.LabelFor(model => model.Note)
</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.DropDownListFor(model => model.TopicID, (SelectList)ViewData["Topics"], "Select")
@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>
<div id="results">
Status
</div>
答案 0 :(得分:1)
如果您想使用Ajax.*
助手,请确保已将以下脚本包含在您的页面中:
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.js")" type="text/javascript"></script>
如果你不包含它,那么就没有什么可以理解Ajax发出的HTML5 data- *属性。* helper和AJAXify这个形式=&gt;表单执行正常提交并呈现结果。