在我的MVC應用程序我有一個使用HTML輔助函數的網格。 EditorTemplate看起來像;MVC:使用DELETE動詞在FF工作,但不是在IE
<tr>
<td>
<%-- Ajax Delete --%>
<% if(Model.LeaveId > 0) { %>
<%: Html.DeleteEmployeeOtherLeave("Delete", Model)%>
<%} %>
</td>
<td><%: Model.LeaveType %></td>
<td><%: Model.MorningOnlyFlag %></td>
<td><%: Model.AfternoonOnlyFlag %></td>
<td><%: Model.DayAmount %></td>
<td><%: String.Format("{0:ddd MMM d yyyy}", Model.Date)%></td>
</tr>
而HTML助手看起來像;
public static MvcHtmlString DeleteEmployeeOtherLeave(this HtmlHelper html, string linkText, Leave _leave)
{
return html.RouteLink(linkText, "Default",
new { _employeeOtherLeaveId = _leave.LeaveId, action = "Delete" },
new { onclick = "$.ajax({url: this.href, type: 'DELETE', success: function(result) {$('#wholepage').html(result);}}); return false;" }
}
我的控制器看起來像;
[HttpGet]
[Authorize(Roles = "Administrator, AdminAccounts, ManagerAccounts")]
public ActionResult EmployeeAbsence()
{
if ((SessionObjects.AbsenceStartDate > DateTime.MinValue) && (SessionObjects.AbsenceEndDate > DateTime.MinValue))
if (SessionObjects.AbsenceSelectedEmployeeId == 0)
return View(new AbsenceViewModel()
{
AbsenceStartDate = SessionObjects.AbsenceStartDate,
AbsenceEndDate = SessionObjects.AbsenceEndDate
});
else
return View(new AbsenceViewModel(
SessionObjects.AbsenceStartDate,
SessionObjects.AbsenceEndDate,
SessionObjects.AbsenceSelectedEmployeeId
));
return View();
}
[AcceptVerbs(HttpVerbs.Delete)]
public ActionResult Delete(int _employeeOtherLeaveId)
{
EmployeeOtherLeaf.Delete(_employeeOtherLeaveId);
return RedirectToAction("EmployeeAbsence");
}
#endregion
使用Delete動作在FF中工作,但在IE中不起作用。用POST代替DELETE動詞似乎阻止它工作。我如何得到這個在IE中工作?
僅供參考:RedirectToAction將不能用於XHR,因爲您期望它... –
IE中究竟發生了什麼?你有錯誤嗎?請求是否發生?哪一種? –
錯誤是System.Web.HttpException:在控制器'SHP.Controllers.EmployeeController'上找不到公共操作方法'Delete'。 – arame3333