方案引起奇怪的行爲: 我有一個觀點和看法裏面我也是一個局部視圖。 在主視圖上我有兩個文本框和一個按鈕。當用戶輸入數據並單擊該按鈕時,數據將添加到數據庫並在部分視圖中以表格格式顯示。jquery.unobtrusive-ajax.min的觀點
局部視圖也有一個刪除鏈接的每一行。爲了支持這個刪除,我必須使用「jquery.unobtrusive-ajax.min」。
問題: 當我點擊按鈕保存數據,就認爲一切都瘋了。整個頁面變得雙倍。請參閱圖片。 但是,如果我刪除了「jquery.unobtrusive-ajax.min」的引用,則問題不存在(儘管如此,刪除does not工作)。
任何人都知道這種行爲,該如何解決呢?
的主視圖:
<%Html.EnableClientValidation(); %>
<% using (Ajax.BeginForm("Create","Program",new AjaxOptions{UpdateTargetId="CreateData"}))
{ %>
<div id="CreateData">
<div>
<%:Html.LabelFor(m=>m.Year) %>
</div>
<div>
<%:Html.TextBoxFor(m=>m.Year) %>
</div>
<div>
<table>
<tr>
<td><%:Html.LabelFor(m=>m.Time) %></td>
<td><%:Html.LabelFor(m=>m.Title) %></td>
<td></td>
</tr>
<tr>
<td><%:Html.TextBoxFor(m => m.Time)%></td>
<td><%:Html.TextBoxFor(m=>m.Title) %></td>
<td><input type="image" value="Register" src="../../Content/images/btnAdd.png"/></td>
</tr>
</table>
</div>
</div>
<div>
<div id="result">
</div>
</div>
<div class="clear"></div>
<script type="text/javascript">
$(function() {
var year = $("#Year").val();
$('#result').load('/Program/Browse?year=2012');
});
</script>
<%} %>
PartialView:
<table>
<% foreach (var item in Model)
{%>
<tr>
<td style="width:150px"><%:Html.Encode(item.Time) %></td>
<td><%:Html.Encode(item.Title) %></td>
<%--<td><%:Html.ActionLink("Delete","Delete",new {ID=item.ID}) %></td>--%>
<td><%:Ajax.ActionLink("Delete", "Delete", new { id = item.ID }, new AjaxOptions
{
Confirm = "Are you sure you want to delete?",
OnComplete = "deleteCompleted",
HttpMethod = "DELETE"
})%></td>
<%--<a onclick="deleteRecord(<%: item.ID %>)" href="JavaScript:void(0)">Delete</a></td>--%>
</tr>
<%} %>
</table>
刪除操作:
[Authorize(Roles = "Admin")]
[AcceptVerbs(HttpVerbs.Delete)]
public ContentResult Delete(int id)
{
var query = (from p in dc.Programme
where p.ID == id
select p).First();
if (query != null)
{
dc.Programme.DeleteObject(query);
dc.SaveChanges();
}
/* return RedirectToAction("Create");*/
return this.Content(" ");
}
replace this this.Content(「」);返回新的EmptyResult(); – Softlion