Understanding MVC Models

In the models I:

public class BidModel
{

    public int id { get; set; }
    public string FirstName{ get; set; }
    public string LastName{ get; set; }
    public int Price{ get; set; }
    public string Date{ get; set; }

} 

Where and how should I define a global list List<BidModel> MyList = new List<BidModel>;so that I can add items to one controller and then delete items from another controller to change the contents of the list wherever I want. OK I know that I am working with a database, but I need this list of offers because I do not want many queries to be based.

+3
source share
4 answers

In View-Controller mode, the responsibility of dispatchers is to pass the correct model before the view, depending on the action you invoke. With that in mind. You do not want to create a global list with BidModel.

MVC 3, dynamic ViewBag.

:

public ActionResult RetreiveAllBids()
{
    var bids = BidRepository.GetAllBids();

    ViewBag.Bids = bids.ToArray();

    return View();
}

, LINQ-to-* , ORM/ . , List .

Edit

, , , , , , , :

  • , -.
  • ,

, , , BidModel :

public IEnumerable<BidModel> Bids
{
   get { return Session["Bids"] as IEnumerable<BidModel>; }
   set { Session["Bids"] = value; }
}

, , // , .

+4

, BidModel - -, . CRUD, -.

, -. - -.

+1

ASP.NET MVC "" ; , , , ( " " ), , , . List<> ; , . LINQ to SQL Entity Framework Microsoft .

+1

ioc, structuremap ninject, . .

0

Source: https://habr.com/ru/post/1791330/


All Articles