Im using MVC 5 and EF 6. There is a viewModel as below which I used it for create view:

public class LeadViewModel
{
    public Leads _leads { get; set; }
    public Addresses _addresses { get; set; }
    public Phones _phones { get; set; }
    public Emails _emails { get; set; }

    public SelectList EmployeesList { get; set; }
    public SelectList IndustryList { get; set; }
    public SelectList LeadSourceList { get; set; }
    public SelectList LeadStatusList { get; set; }

    public SelectList AddressTypeList { get; set; }
    public SelectList CityList { get; set; }

    public SelectList PhoneTypeList { get; set; }
}

Now I want to pass some of its fields to Index view. How should I do that?

Here is more info about other tables:

1-Lead Class:

public partial class Leads
{
    public Leads()
    {            
        this.LeadAddresses = new HashSet<LeadAddresses>();
        this.LeadContacts = new HashSet<LeadContacts>();
        this.LeadEmails = new HashSet<LeadEmails>();
        this.LeadPhones = new HashSet<LeadPhones>();
    }

    [Key]
    public int LeadID { get; set; }
    public string NamePrefix { get; set; }
    public string Title { get; set; }
    public string FirstName { get; set; }]
    public string LastName { get; set; }
    [NotMapped]       
    public string FullName { get { return NamePrefix + " " + FirstName + " " + LastName; } }
    public int EmployeeID { get; set; }
    public int LeadStatusID { get; set; }


    public virtual Employees Employees { get; set; }
    public virtual ICollection<LeadEmails> LeadEmails { get; set; }
    public virtual ICollection<LeadAddresses> LeadAddresses { get; set; }
    public virtual ICollection<LeadPhones> LeadPhones { get; set; }
    public virtual LeadStatus LeadStatus { get; set; }
}

Phones Class:

public partial class Phones
{
    public Phones()
    {            
        this.LeadPhones = new HashSet<LeadPhones>();
    }

    [Key]
    public int PhoneID { get; set; }
    public int PhoneTypeID { get; set; }              
    public string PhoneNo { get; set; }    
    public bool IsAllowed { get; set; }

    public virtual ICollection<LeadPhones> LeadPhones { get; set; }
    public virtual PhoneTypes PhoneTypes { get; set; }
}

LeadPhones junction table:

public partial class LeadPhones
{
    [Key]
    public int LeadPhoneID { get; set; }
    public int LeadID { get; set; }
    public int PhoneID { get; set; }

    public virtual Leads Leads { get; set; }
    public virtual Phones Phones { get; set; }
}

In index view I want to display just:

Leads.FullName
Leads.Title
Leads.LeadStatus.Status
Leads.Employees.FullName
Leads.Phones.PhoneNo
Leads.Industries.Industry

Should I pass the viewModel to Index view from controller? If so, how? And how should I use that in Index view?

Related posts

Recent Viewed