1
AJAX 요청이 완료된 후 PartialView에 저장된 스레드를 렌더링 할 때 ASP MVC 3에 문제가 발생했습니다. 여기 내 두 뷰의 코드이다ASP MVC에서 PartialView를 렌더링 할 때 문제가 발생했습니다.
@model ICollection<Foo.ViewModels.OrderSearchViewModel>
@using Foo.Helpers
@{
ViewBag.Title = "Sales Order Lookup";
}
@using (Ajax.BeginForm(new AjaxOptions()
{
HttpMethod = "GET",
UpdateTargetId = "results",
InsertionMode = InsertionMode.Replace
}))
{
@*"Search","OrderSearch",FormMethod.Get*@
<div id="Criteria" style="width: 800px;margin-left:10%">
<table id="tblSearchCriteria" class="FunnyRedLine" width="100%">
<!-- Many boring search fields here -->
<td style="width: 40%">
<input type="submit" value="Search" class="Text" />
</td>
</tr>
</table>
</div>
}
@Html.Partial("SearchResults",Model)
이 부분도
@model ICollection<Foo.ViewModels.OrderSearchViewModel>
@using Foo.Helpers
@if (Model.Count > 0)
{
<div id="results" style="width: 800px; margin-left:10%">
<table id="tbl">
<tr>
<th>Sod Id</th>
<th>Sales Ref</th>
<th>SOP Ref</th>
<th>Order Date</th>
<th>Value</th>
<th>Status</th>
<th>Del Date</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td width="30" align="center">@Html.DisplayFor(modelItem => item.Id)</td>
<td width="30" align="center">@Html.DisplayFor(modelItem => item.SalesPersonRef)</td>
<td width="200" align="center">@Html.DisplayFor(modelItem => item.SOPRef)</td>
<td width="100" align="left">@Html.FormatDate(item.OrderDate)</td>
<td width="100" align="right">@Html.FormatNumber(item.Value,"C2")</td>
<td width="300" align="left">@Html.DisplayFor(modelItem => item.Status)</td>
<td width="100" align="left">@Html.FormatDate(item.DelDate)</td>
</tr>
}
</table>
</div>
}
가되고 이는 본 AJAX 요청 작동
public class OrderSearchController : Controller
{
//
// GET: /OrderSearch/
[Ajax(false)]
public ActionResult Index()
{
var viewModel = new List<OrderSearchViewModel>();
ViewBag.SalesPeople = GetAllSalesPeople()
ViewBag.OrderTypes = GetAllOrderTypes()
return View(viewModel);
}
[Ajax(true)]
public ActionResult Index(string id, string startDate, string endDate, string postCode, string salesPersonId, string salesPersonRef,
string orderTypeId, string serialNo, string customerPO)
{
var service = new eSodSrv();
var viewModel = service.GetHeaders(id.ToInt32(), salesPersonId.ToInt32(), orderTypeId.ToInt32(), startDate.ToDate(), endDate.ToDate(), postCode, customerPO, serialNo, salesPersonRef);
return PartialView("SearchResults",viewModel);
}
}
, 그것은 입력 내 컨트롤러 올바른 방법 (Ajax는 Request.IsAjaxRequest()를 검사하는 사용자 정의 속성)이며 데이터를 리턴하므로 뷰가 렌더링되지 않는 이유는 무엇입니까?
감사합니다. 그러나 이제는 그가 의심의 여지가있다, ASP MVC는 해당 div의 부분보기 SearchResults를 렌더링해야한다는 것을 어떻게 알 수 있습니까? – groovejet
@groovejet UpdateTargetId를 해당 div의 id로 설정했기 때문입니다. – frennky