【发布时间】:2011-07-06 14:24:56
【问题描述】:
有没有办法刷新局部视图的一部分,或者我应该将该部分分解成它自己的单独局部视图?我面临的问题是,每当我提交表单时,整个部分视图都会更新,复制我的表单输入,但我真的只希望“noteList”更新。以下是一些可能有用的详细信息。
在我的项目中,我有一个页面被分成单独的选项卡,每个选项卡都是它自己的部分视图,当有人单击该选项卡时会加载该视图。我现在关注的是一个笔记标签。
下面是捕捉帖子的标记和控制器。
<div id="noteList">
@Html.Grid(Model).Columns(column => {
column.For(x => x.TimeStamp);
column.For(x => x.UserName);
column.For(x => x.Note);
}).Attributes(Style => "text-aligh: center", @Class => "linkGrid")
</div>
<div id="addNoteForm">
<h2>Add New Note</h2>
@using (Ajax.BeginForm("AddNote", "Dispute", null, new AjaxOptions { UpdateTargetId = "noteList" }, new { id = "AddNote" })) {
@Html.Hidden("DisputeID", ViewData["DisputeID"])
<div class="editor-multiline-field">
@Html.Editor("Note", "editor-multiline-field")
</div>
<input type="submit" value="Add Note" />
}
</div>
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult AddNote(FormCollection collection) {
if (this.ModelState.IsValid) {
DisputeNote newNote = new DisputeNote(repository.Get(int.Parse(collection["DisputeID"])), User.Identity.Name, collection["Note"]);
repository.SaveForUpdate<DisputeNote>(newNote);
}
var Notes = repository.GetNotesForDispute(int.Parse(collection["DisputeID"]));
ViewData["DisputeID"] = int.Parse(collection["DisputeID"]);
return PartialView("NoteList", Notes);
}
我知道将它分成另一个部分视图会起作用,但我很好奇是否有其他方法可以做到这一点。
【问题讨论】:
标签: c# asp.net-mvc-3 jquery