简体   繁体   中英

ASP.NET MVC 4 Model is null after post

Hello this is my product controller i have one one table and one form in view. When I submit model. Product everything ok but when I return view from HttpPost Index model is always null.

If I reload page model is filled.

  public ActionResult Index()
     {
        var model = new ProductViewModel();
        var suppliers = new List<Supplier>();
        var categories = new List<GoodsCategory>();
        using (var session = _sessionFactory.OpenSession())
        {
            model.Products = session.Query<Product>().ToList();
            suppliers = (from d in session.Query<Supplier>()
                         select new Supplier
                             {
                                 Id = d.Id,
                                 Name = d.Name
                             }).ToList();

            categories = session.Query<GoodsCategory>().ToList();

            model.Suppliers = suppliers;
            model.Categories = session.Query<GoodsCategory>().ToList();
        }

        return View(model);
    }

    [HttpPost]
    public ActionResult Index(ProductViewModel model)
    {
        return View()
    }

Does anybody knows whats wrong in my code?

type return View(model); in post action

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM