2016-10-24 2 views
0

Контроллер:DropDownList не dispaying MVC

public async Task<ActionResult> TeamTaskSearchDetails1(string claimId, string type) 
{ 
      int eqClaimId; 
      if (false == int.TryParse(claimId, out eqClaimId)) 
       return null; 

     var AssigineeList = await this.handsService.GetTeamTask(); 
     var content = from p in AssigineeList.Data.ToList() 
         orderby p.claimid 
         select new { p.claimid, p.Assiginee }; 
     var serviceResult = await this.handsService.GetTeamTaskDetails(Convert.ToString(eqClaimId)); 
     var claim = serviceResult.ServiceResponse; 
     var authorizationData = this.AuthorizationData(); 
     var regId = authorizationData.CurrentRegionId; 
     XDocument xdoc = new XDocument(); 
     xdoc = XDocument.Parse(claim); 
     var result = xdoc.Element("Claim").Descendants(); 


     var StartDate = xdoc.Descendants().Where(e => e.Name.LocalName == "StartDate").FirstOrDefault().Value; 
     var EndDate = xdoc.Descendants().Where(e => e.Name.LocalName == "EndDate").FirstOrDefault().Value; 
     var ForensicDueDate = xdoc.Descendants().Where(e => e.Name.LocalName == "ForensicDueDate").FirstOrDefault().Value; 
     var FirstName = xdoc.Descendants().Where(e => e.Name.LocalName == "FirstName").FirstOrDefault().Value; 
     var status = xdoc.Descendants().Where(e => e.Name.LocalName == "status").FirstOrDefault().Value; 

     Equip.Models.TeamTaskSearchDetails.ClaimDetails claimdtl = new Equip.Models.TeamTaskSearchDetails.ClaimDetails() 
     { 

      StartDate = StartDate, 
      EndDate = EndDate, 
      ForensicDueDate = ForensicDueDate, 
      FirstName = FirstName, 
      status = status, 
     }; 
     var x = content.ToList().Select(c => new List<SelectListItem> 
     { 
     new SelectListItem 
     { 
      Text = c.Assiginee, 
      Value =Convert.ToInt32(c.claimid).ToString(), 
     }, 

     }).ToList(); 

     ViewBag.Task = x; 
     this.ViewBag.Type = type; 
     return this.PartialView("_TeamTaskClaimSearch", claimdtl); 
    } 

Модель Класс:

public class ClaimDetails 
{ 

    public int Assigineeid { get; set; } 

    public List<ClaimDetails> AssigineeList { get; set; } 
    public int ID { get; set; } 
    public string claimid { get; set; } 
    //public List<SelectListItem> claimid { get; set; } 
    public string contactID { get; set; } 
    public string Creator { get; set; } 
    public string Description { get; set; } 
    public string status { get; set; } 
    public string StartDate { get; set; } 
    public string EndDate { get; set; } 
    public string ForensicDueDate { get; set; } 
    public string ForensicDueTime { get; set; } 
    public string PatientFirstName { get; set; } 
    public string PatientLastName { get; set; } 
    public string Client { get; set; } 
    public string ProviderName { get; set; } 
    public string FirstName { get; set; } 
    public string LastName { get; set; } 
    public string PreScreen { get; set; } 
    public string Priority { get; set; } 
    public string Edit { get; set; } 
    public string Comment { get; set; } 


    public string Assiginee 
    { 
     get 
     { 
      return string.Format("{0} {1}", this.FirstName ?? string.Empty, this.LastName ?? string.Empty).Trim(); 
     } 
     set 
     { 

     } 

    } 
    public string Patient 
    { 
     get 
     { 
      return string.Format("{0} {1}", this.PatientFirstName ?? string.Empty, this.PatientLastName ?? string.Empty).Trim(); 
     } 

    } 

} 

} 

Вид Bind DropDown:

@Html.DropDownListFor(m=>m.claimid, new SelectList(ViewBag.Task, new { @class = "form-control", @id = "dropdown" })) 

Мне нужно Bind Assiginee в DropDownList, Шифрование до значения приходят к контроллеру

enter image description here

+0

Try '@ Html.DropDownList ("Task", нулевой htmlAttributes: новый {@class = "форм-контроль", @ id = "dropdown"}) ' – SeM

+0

Вместо использования' ViewBag' вы можете создать свойство 'SelectList' в модели' ClaimDetails' и передать его для просмотра как '@ Html.DropDownListFor (m => m.claimid, Model. SelectionList, new {@class = "form-control", @id = "dropdown"})) '. –

ответ

0

Укажите поля, что необходимо принять для значения и текста

var x = content.ToList().Select(c => new SelectListItem 

      { 
       Text = c.Assiginee, 
       Value =Convert.ToInt32(c.claimid).ToString(), 
      } 

      ).ToList(); 


@Html.DropDownListFor(m=>m.claimid, new SelectList(ViewBag.Task, "Value", "Text" , new { @class = "form-control", @id = "dropdown" })) 
+0

его отображение Сообщение об ошибке для – SriramNandha

+0

Исключение типа «System.Web.HttpException» произошло в System.Web.dll, но не было обработано в коде пользователя Дополнительная информация: DataBinding: 'System.Collections.Generic.List'1 [ [System.Web.Mvc.SelectListItem, System.Web.Mvc, Version = 5.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35]] 'не содержит свойства с именем «Значение». – SriramNandha

+0

Пожалуйста, помогите. – SriramNandha