【问题标题】:ASP.NET MVC 4 Model is null after post发布后 ASP.NET MVC 4 模型为空
【发布时间】:2013-03-07 10:53:50
【问题描述】:

您好,这是我的产品控制器,我有一张一张桌子和一张表格。当我提交模型时。产品一切正常,但是当我从 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()
    }

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

【问题讨论】:

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


    【解决方案1】:

    在后期操作中输入return View(model);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-13
      • 2014-01-01
      • 2014-08-17
      • 2021-12-19
      • 2013-08-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多