One select list consisting of two classes

86 views Asked by At

I have 3 classes

public class A
{
    public decimal id {get; set;}
    public virtual B? BNavigation {get; set;};
    public virtual C? CNavigation {get; set;};
}

public class B
{
    public int id {get; set;}
    public string title {get; set;}
    [...]

}

public class C
{
    public int id {get; set;}
    public string title {get; set;}
    [...]
}

I try example above, string concatenation, tried to do it with LINQ. I realized that I need to do this through an auxiliary class.

And i want to make SelectList by class A

Example:

ViewData["A"] = new SelectList( A,"Id", "BNavigation.title - CNavigation.title");

How can i do it ?

1

There are 1 answers

0
dmmhlchk On

I want this post to be closed, because i found block of code which decide my problem

ViewBag.PackageId = db.Packages.Where(p => p.status == "A")
  .Select(p => new SelectListItem
  {
         Text = p.u_package_id + "-" + p.package_nme,
         Value = p.u_package_id.ToString()
  });