在我的MVC 4应用程序中,我正在尝试使用Ajax表单来实现对“预订”存储库的搜索。
我的观点:(观点/预订/索引):
@model IEnumerable<RentalsForceProject.Models.Reservation>
@{
ViewBag.Title = "Reservations Center";
ViewBag.current = "Reservation";
}
@section featured {
@Html.Partial("_Navigator")
}
@using (Ajax.BeginForm(
new AjaxOptions
{
HttpMethod = "get",
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "ReservaionList"
}))
{
<input type="search" name="searchTerm" />
<input type="submit" name="Search By Contact" />
}
<p>
<input type="button" value="Create New" class="greenButton" style="margin-top:20px;" onclick="location.href='@Url.Action("Create", "Reservation")'"/>
</p>
@Html.Partial("_Reservation", Model)
我的部分视图(Views / Reservation / _Reservation):
@model IEnumerable<RentalsForceProject.Models.Reservation>
<div id="ReservaionList" class="table-responsive">
<table class="table table-ordered">
<tr>
<th>
Reservation
</th>
<th>
Name
</th>
<th>
Dates
</th>
<th>
# Nights
</th>
<th>
Status
</th>
<th></th>
</tr>
@foreach (var res in Model)
{
<tr>
<td>
@res.ID
</td>
<td>
@if (res.Contact != null) {
@Html.ActionLink(res.Contact.FirstName + " " + res.Contact.LastName, "Details", "Contact", new { id=res.Contact.ID }, null)
//@res.Contact.LastName @: @res.Contact.LastName
}
</td>
<td>
@if (res.Request != null) {
@res.Request.StartDate @:- @res.Request.EndDate
}
</td>
<td>
@res.calculteNights()
</td>
<td>
@if (res.Status != null) {
@res.Status
}
</td>
<td>@Ajax.ActionLink("Edit", "Edit", "Reservation", new { id = res.ID }, new AjaxOptions() { HttpMethod = "Post" }) | @Ajax.ActionLink("View", "Details", new { id = res.ID }, new AjaxOptions() { HttpMethod = "Post" }) | @Ajax.ActionLink("Delete", "Delete", new { id = res.ID }, new AjaxOptions() { HttpMethod = "Post" })</td>
</tr>
}
</table>
</div>
我的索引ActionResult:
public ActionResult Index(string searchTerm = null)
{
if (unitOfWork.currentClient == null)
{
return RedirectToAction("LogOn", "Account");
}
else
{
ViewBag.currentClient = unitOfWork.currentClient;
if (Request.IsAjaxRequest() && searchTerm != null)
return PartialView("_Reservaion", unitOfWork.currentClient.getAllReservationsBySearchTerm(searchTerm));
return View(unitOfWork.currentClient.getAllReservations());
}
}
当我在“搜索”按钮下午餐时,我可以看到它创建了nesessary模型到局部视图,但视图中没有任何反应。 我尝试使用Chrome开发者工具 - &gt; F12 - 网络选项卡,发现了这个例外:
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The partial view '_Reservaion' was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Reservation/_Reservaion.aspx
~/Views/Reservation/_Reservaion.ascx
~/Views/Shared/_Reservaion.aspx
~/Views/Shared/_Reservaion.ascx
~/Views/Reservation/_Reservaion.cshtml
~/Views/Reservation/_Reservaion.vbhtml
~/Views/Shared/_Reservaion.cshtml
~/Views/Shared/_Reservaion.vbhtml
任何想法?