我的项目中有两个模型,SupplierRow.cs
using System;
namespace Argussite.SupplierServices.ViewModels
{
public class SupplierRow
{
public Guid Id { get; set; }
public string FullName { get; set; }
public bool Subscribed { get; set; }
public bool Active { get; set; }
public int Visits { get; set; }
}
}
和UserRow.cs
using System;
namespace Argussite.SupplierServices.ViewModels
{
public class UserRow
{
public Guid Id { get; set; }
public string FullName { get; set; }
public string Name { get; set; }
public string Email { get; set; }
public int Status { get; set; }
public int Role { get; set; }
}
}
然后我在一个控制器中使用第一个模型
public ActionResult Grid(bool? active)
{
var page = Context.Suppliers.AsNoTracking()
.WhereIf(active != null, e => e.Active == active)
.Select(e => new SupplierRow
{
Id = e.Id,
FullName = e.FullName,
Active = e.Active,
Visits = e.Visits
})
.ToList();
return PartialView("_Grid", page);
}
并在其他控制器中使用第二个模型
public class AdminSuppliersAccountsController : BaseController
{
public ActionResult Index(Guid id)
{
var supplierOfUser = Context.Suppliers.AsNoTracking()
//.Include(e => e.Supplier)
.FirstOrDefault(e => e.Id == id);
ViewData.Add("id", id);
ViewData.Add("SupplierFullName", supplierOfUser.FullName);
return View();
}
public ActionResult Grid(int? status, Pager pager, Guid? supplierId)
{
var page = Context.Users.AsNoTracking()
.Where(e => e.SupplierId == supplierId)
.WhereIf(status != null, e => (e.Status == status))
.Select(e => new UserRow
{
Id = e.Id,
FullName = e.FullName,
Email = e.Email,
Name = e.Name,
Status = e.Status,
Role = e.Role
})
.GetPage(pager, Sorter.Asc<UserRow, string>(e => e.FullName));
return PartialView("_Grid", page);
}
但我需要在第一个控制器中添加检查来自第二个模型的所有用户是否具有Inactive状态,然后在视图中使用它。
我怎么能这样做?
我想,我需要在第一个模型public bool AllUnactive { get; set; }
中添加一个新属性,但我该怎么做呢?