Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Match
- {
- public int Id { get; set; }
- public string Team1 { get; set; }
- public string Team2 { get; set; }
- public int Rate { get; set; }
- public int BO { get; set; }
- }
- public class Person
- {
- public int Id { get; set; }
- public string Name { get; set; }
- public int Days { get; set; }
- public DateTime Date { get; set; }
- }
- public class MatchContext : DbContext
- {
- public DbSet<Match> Matches { get; set; }
- public DbSet<Person> Persons { get; set; }
- }
- public class NeuroController : Controller
- {
- MatchContext db = new MatchContext();
- public ActionResult Index()
- {
- return View(db);
- }
- protected override void Dispose(bool disposing)
- {
- db.Dispose();
- base.Dispose(disposing);
- }
- }
- @model IEnumerable<NB.Models.Match>
- @{
- ...
- public class ViewModel
- {
- public IEnumerable<Match> Matches {get;set;}
- public IEnumerable<Person> Persons {get;set;}
- //или же можно указать конкретные свойства из классов
- }
- public class NeuroController : Controller
- {
- public ActionResult GetViewModel()
- {
- var db = new MatchContext();
- var matches = db.Matches.ToList();
- var persons = db.Persons.ToList();
- var model = new ViewModel { Matches = matches, Persons = persons};
- return View(model);
- }
- }
Add Comment
Please, Sign In to add comment