시나리오 : 뷰가 있고 그 뷰 내부에 부분 뷰가 있습니다. 기본보기에는 두 개의 텍스트 상자와 버튼이 있습니다. 사용자가 데이터를 입력하고 버튼을 클릭하면 데이터베이스에 추가 된 데이터가 부분 뷰에 표 형식으로 표시됩니다.jquery.unobtrusive-ajax.min 뷰에 이상한 동작이 발생했습니다.
부분보기에는 각 행에 대한 삭제 링크도 있습니다. 삭제를 지원하기 위해 "jquery.unobtrusive-ajax.min"을 사용해야했습니다.
문제점 : 버튼을 클릭하여 데이터를 저장하면보기의 모든 것이 미쳐갑니다. 전체 페이지가 두 배가됩니다. 이미지를 참조하십시오. 하지만 "jquery.unobtrusive-ajax.min"에 대한 참조를 삭제하면 문제가 존재하지 않습니다 (삭제해도 작동하지 않습니다).
누구나이 동작을 알고, 어떻게 해결합니까 ??
주 화면 :
<%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(" ");
}
바꾸기 return this.Content (""); 반환과 함께 새로운 EmptyResult(); – Softlion