我正在嘗試使用部分視圖顯示國家/地區員工詳細資訊......它基本上被稱為部分視圖,但沒有在其中顯示資料。這是我的索引頁面代碼
<select class="form-control" name="CountryID" id="CountryID" onchange="getAllEmployee(this)">
<option value="null">Select Name</option>
@foreach (var varAllRecord in ViewBag.VBCountry)
{
<option id="@varAllRecord.CountryID" value="@varAllRecord.CountryID ">@varAllRecord.CountryName </option>
}
</select>
<div id="dvEmployeeResult">
<partial name="_ClassesEmployees" />
</div>
這是我的 AJAX CALL 詳細資訊
<script type="text/javascript">
var valueID;
var datais;
function getAllEmployee(selectObject) {
valueID = selectObject.value;
$.ajax({
type: "POST",
url: "@Url.Action("GetEmployeeDataByCountryID", "Dynamic")",
data: { EmployeeID: valueID },
@*dataType: "Text",*@
@*contentType: "application/text",*@
success: function (data) {
// alert("In Success");
console.log(data);
$("#dvEmployeeResult").html(data.responseText);
},
error: function (data) {
// debugger;
$("#dvEmployeeResult").html(data.responseText);
}
});
console.log(valueID)
}
</script>
public async Task<IActionResult> Index()
{
await GetCountryList();
return View();
}
public async Task<bool> GetCountryList()
{
List<tblCountryList> theCountryList = await _dbCountryListContext.GetAllCountryListAsync();
ViewBag.VBCountry = theCountryList;
return true;
}
[HttpPost]
public async Task<PartialViewResult> GetEmployeeDataByCountryIDAsync(string EmployeeID)
{
var CountryID = EmployeeID;
List<Account> theEmployeeList = await _dbAccountContext.GetAllEmployeeListAsync(CountryID);
ViewBag.datasourceEmplyee = theEmployeeList;
return PartialView("~/Views/Dynamic/_ClassesEmployees.cshtml", ViewBag.datasourceEmplyee);
}
這是我的部分視圖代碼。
@model IEnumerable<MasterProject.Models.Account>
@if(ViewBag.datasourceEmplyee != null)
{
@foreach (var item in (List<Account>)ViewBag.datasourceEmplyee)
{
@item.RowID
@item.FirstName
@item.CountryID
}
}
你能告訴我出了什么問題嗎?我正在努力作業,但沒有得到解決方案。資料已獲取,但不知何故未顯示在視圖中。
uj5u.com熱心網友回復:
修復動作
[HttpPost]
public async Task<PartialViewResult> GetEmployeeDataByCountryIDAsync(string CountryID)
{
List<Account> theEmployeeList = await _dbAccountContext.GetAllEmployeeListAsync(CountryID);
return PartialView("~/Views/Dynamic/_ClassesEmployees.cshtml", theEmployeeList);
}
但是使用 CountryId 的 GetAllEmployeeListAsync 不適合我
同樣的方式檢查部分視圖,我認為應該是
@model List<MasterProject.Models.Account>
@if(model != null && @model.Count > 0)
{
@foreach (var item in model)
{
@item.RowID
@item.FirstName
@item.CountryID
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/425433.html
標籤:C# asp.net-mvc asp.net-mvc-4 asp.net-mvc-3
上一篇:如何在頁面之間創建鏈接?
下一篇:如何從瀏覽器瀏覽本地主機網站
