Click here to Skip to main content
14,733,448 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have MVC framework User Table and my own Community Table. I also have a relationship CommunityUser table. I am virtually connecting CommunityUser table with community Table. Here is my Community class

public class Community
    public int CommunityID { get; set; }

    public string CommunityName { get; set; }

    public string CommunityDomain { get; set; }
    public string CommunityAbout { get; set; }
    public string CommunityLogo { get; set; }

    public int PrivacyID { get; set; }

    public string CommunityAdmin { get; set; }
    public virtual PrivacyLevel PrivacyLevel { get; set; }
    public virtual  ICollection<CommunityUser> CommunityUsers { get; set; }

    public Community()
        CommunityUsers = new Collection<CommunityUser>();


I want to use User Table and Community User Table on my index page. I have created a ProfileDataViewModel having these two tables.

public class ProfileDataViewModel
    public ApplicationUser User { get; set; }
    public List<CommunityUser> CommunitiesList { get; set; }

Now when I am using this view model on my index function, it is throwing an exception. Here is my index function

public ActionResult Index()
        var thisUser = db.Users.Where(u => u.UserName == User.Identity.Name).SingleOrDefault();

        var myDashboard = new ProfileDataViewModel()
            User = thisUser,
            CommunitiesList = db.CommunityUsers.Include(x => x.Community).Where(u => u.UserID==thisUser.Id).ToList()

        return View(myDashboard);

What I have tried:

when I am using this view model on my index function, it is throwing an exception. Here is my index function
F-ES Sitecore 19-Apr-17 7:32am
If you didn't post the exception you are getting because you don't appreciate that it is important in helping solve the problem then maybe programming isn't for you.
j snooze 19-Apr-17 17:47pm
Yes, the error and assuming you did some debugging on your own, the line of code it is occurring on.
Member 14552976 29-Aug-19 2:58am
please post the actual exception you get while running?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900