-1

大家好,以下是我的按需供稿模型代码

public class OndemandFeedModel
{
    public CountryModel Country { get; set; }
    public FieldSelectModel Fields { get; set; }
    public FilterSelectModel Filters { get; set; }
}


 public class FieldSelectModel
    {
    public List<FieldGroup> FieldGroup { get; set; }
   }


 public class FieldGroup
 {
    public string GroupName { get; set; }
    public List<FieldModel> Fields { get; set; }
}

public class FieldModel
{
    public bool IsSelected { get; set; }
    public int FieldId { get; set; }
    public string FieldName { get; set; }
    public string UserDefinedFieldName { get; set; }
    public string FieldGroup { get; set; }
    public string Country { get; set; }

}

当我点击 Httppost 时,它会给出以下错误

在此处输入图像描述 在此处输入图像描述

我不知道出了什么问题。谁能帮我

4

2 回答 2

0

我想您需要查看Request.Form.AllKeys发布的内容。

您的 HTML 输入字段应映射模型对象图的分层命名,否则模型绑定器不会将其绑定到模型。

此外,首先,在发布集合时,您可以发布一个隐藏的集合的起始索引(如果它不是 0)。

于 2013-07-23T06:12:05.540 回答
0

根据上面的代码[HttpPost]不应该与 Index 方法集成,因为 Index 方法应该总是[httpGet],否则它会给出 404 错误。如前所述,在页面加载时它总是给出空值。您可以从以下示例中获取帮助:

interface IProductRepository
{
IEnumerable<Product> GetAll();
}

public class Product
{
    [Display(Name = "Product ID")]
    public int ID { get; set; }

    [Display(Name = "Product Name")]
    public string Name { get; set; }

    [Display(Name = "Product Category")]
    public string Category { get; set; }

    [Display(Name = "Product Price")]
    public decimal Price { get; set; }
}

public class ProductRepository 
{
    private List<Product> products = new List<Product>();

    public ProductRepository()
    {
        products.Add(new Product { ID = 1, Name = "xyz", Category = "Cat A", Price = 1 });
        products.Add(new Product { ID = 2, Name = "xyz", Category = "Cat B", Price = 100 });
        products.Add(new Product { ID = 3, Name = "xyz", Category = "Cat C", Price = 1000 });
        products.Add(new Product { ID = 4, Name = "xyz", Category = "Cat D", Price = 10000 });
    }

    public IEnumerable<Product> GetAll()
    {
        return products;
    }        

}

    public ActionResult Index(Product model)
    {   
        repository.GetAll();
        //put foreach() here...
        return View();
    }
于 2013-07-23T07:43:26.323 回答