部分视图数据未显示在其中
Partial View data is not display in it
我正在尝试使用局部视图显示国家/地区的员工详细信息...它基本上称为局部视图,但没有在其中显示数据。
这是我的索引页代码
<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 通话详情
<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
}
}
你能告诉我哪里出了问题吗?我非常努力地工作,但没有得到解决方案。数据已获取,但不知何故未显示在视图中。
修复操作
[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
}
}
我正在尝试使用局部视图显示国家/地区的员工详细信息...它基本上称为局部视图,但没有在其中显示数据。 这是我的索引页代码
<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 通话详情
<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
}
}
你能告诉我哪里出了问题吗?我非常努力地工作,但没有得到解决方案。数据已获取,但不知何故未显示在视图中。
修复操作
[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
}
}