ASP.NET MVC 4 Model在发布后​​为null

时间:2013-03-07 10:53:50

标签: c# asp.net-mvc model http-post

您好这是我的产品控制器我有一个表和一个表单在视图中。当我提交模型。产品一切正常但是当我从HttpPost返回视图时,索引模型总是为空。

如果我重新加载页面模型已填满。

  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()
    }

有人知道我的代码中有什么问题吗?

1 个答案:

答案 0 :(得分:4)

在帖子操作中输入return View(model);

相关问题