@Ajax.ActionLink() メソッドを使用してデータを取得したい。私は次の方法で試しました
Create.chtml
function UpdatePoDetails() {
document.getElementById("poSearchbtn").href = "/MaterialReceivePO/SearchPO?searchID=" + document.getElementById('POID').value
}
@using (Ajax.BeginForm(new AjaxOptions
{
UpdateTargetId = "searchData",
LoadingElementId = "loading"
}
))
{
<input id="POName" type="text" />
@Ajax.ActionLink("Search", "SearchPO", null, new AjaxOptions
{
UpdateTargetId = "PoDetailsDiv",
HttpMethod = "GET"
},
new
{
onclick = "UpdatePoDetails()" ,
id = "poSearchbtn"
}
)
}
@using (Ajax.BeginForm(new AjaxOptions
{
UpdateTargetId = "MainBody",
LoadingElementId = "loading"
}))
{
<div id="PoDetailsDiv">
</div>
}
コントローラー方式
public ActionResult SearchPO(string searchID)
{
int id = int.Parse(searchID);
List<PurchaseOrderDetailsModel> podetails = (
from c in po.GetPoListDetails(id)
select new PurchaseOrderDetailsModel()
{
PoDetailsID = c.PoDetailsID,
ItemID = c.ItemID.Value,
Quantity = c.Quantity,
UnitPrice = c.UnitPrice,
TotalPrice = c.TotalPrice,
DiscountPer = c.DiscountPer,
FinalPrice = c.FinalPrice,
CurrencyID = c.CurrencyID,
ProductID = c.ItemID.Value,
ProductName = c.ProductName,
ProductCode = c.ProductCode,
Description = c.Description
}
).ToList();
return View("SearchPO",podetails);
}
SearchPO.chtml
@model IEnumerable<ERP_Web.Areas.Inventory.Models.PurchaseOrderDetailsModel>
<table class="grid-table">
<tr>
<th>
Product Name
</th>
<th>
Code
</th>
<th>
Quantity
</th>
<th>
Unit price
</th>
<th>
Total
</th>
<th>
Discount
</th>
<th>
Final price
</th>
<th>
Receive Quantity
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.ProductName)
</td>
<td>
@Html.DisplayFor(modelItem => item.ProductCode)
</td>
<td>
@Html.DisplayFor(modelItem => item.Quantity)
</td>
<td>
@Html.DisplayFor(modelItem => item.UnitPrice)
</td>
<td>
@Html.DisplayFor(modelItem => item.TotalPrice)
</td>
<td>
@Html.DisplayFor(modelItem => item.DiscountPer)
</td>
<td>
@Html.DisplayFor(modelItem => item.FinalPrice)
</td>
<td>
@Html.TextBox("reQuantity");
</td>
</tr>
}
</table>
問題は、Ajaxリンクをクリックするとコントローラーに移動することです。コントローラーコードはうまく実行されますが、最後に、戻るときに SearchPO ビューを呼び出しません。コードのどこが間違っているか、または何が欠けているか。何か助けて??