Linq join query displayed in MVC view

I am trying to display a linq connection request in a partial web view.

Here is my request in my controller:

public ActionResult InactiveUsers()
        {
            using (ModelContainer ctn = new ModelContainer())
            {
                DateTime duration = DateTime.Now.AddDays(-3);

                var inactive = from usrs in ctn.aspnet_Users
                               where usrs.LastActivityDate <= duration
                               join o in ctn.Groups on
                               usrs.UserId equals o.UserID
                               select new
                               {
                                   usrs.UserName,
                                   usrs.LastActivityDate,
                                   o.PrimaryPhoneNumber,
                               };

                return View(inactive.ToList());
            }

        }

I am a little confused what to do next. I am familiar with adding strongly typed views using models, but what happens in my case when I have a connection request?

If anyone could point me in the right direction, I would be very grateful.

Thank.

+5
source share
2 answers

Instead of returning IEnumerable of anonymous types, you can create a class for the result of the union, and then create a model for it as usual:

            var inactive = from usrs in ctn.aspnet_Users
                           where usrs.LastActivityDate <= duration
                           join o in ctn.Groups on
                           usrs.UserId equals o.UserID
                           select new InactiveUser(usrs.UserName, usrs.LastActivityDate, o.PrimaryPhoneNumber);

InactiveUser, , , .

+3

ViewModel. , , . .

, , / . . -, , intellisense .

+4

All Articles