简体   繁体   English

部分视图数据未显示在其中

[英]Partial View data is not display in it

I am trying to display countrywise employee details using partial view... It is basically called the Partial view but did not display data in it.我正在尝试使用部分视图显示国家/地区的员工详细信息...它基本上称为部分视图,但未在其中显示数据。 Here is my INDEX PAGE CODE这是我的索引页代码

 <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>

Here is my AJAX CALL Details这是我的 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);
        }

Here is my partial view code.这是我的部分视图代码。

@model IEnumerable<MasterProject.Models.Account>

@if(ViewBag.datasourceEmplyee != null)
{
@foreach (var item in (List<Account>)ViewBag.datasourceEmplyee)
{
    @item.RowID
    @item.FirstName
    @item.CountryID
}
}

can you please suggest to me what went wrong?你能告诉我哪里出了问题吗? I am working very hard but did not get the solution.我非常努力地工作,但没有得到解决方案。 Data is fetched but somehow not displayed in the view.数据已获取但不知何故未显示在视图中。

fix action修复动作

[HttpPost]      
public async Task<PartialViewResult> GetEmployeeDataByCountryIDAsync(string CountryID)
{
  List<Account> theEmployeeList = await _dbAccountContext.GetAllEmployeeListAsync(CountryID);

 return PartialView("~/Views/Dynamic/_ClassesEmployees.cshtml", theEmployeeList);
}

but GetAllEmployeeListAsync using CountryId doesn't look right for me但是使用 CountryId 的 GetAllEmployeeListAsync 不适合我

the same way check the partial view, I think it should be同样的方法查看partial view,我觉得应该是

@model List<MasterProject.Models.Account>

@if(model != null && @model.Count > 0)
{
     @foreach (var item in model)
     {
    @item.RowID
    @item.FirstName
    @item.CountryID
   }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM