以下是我的ondemand Feed模型代码
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时会出现以下错误
我不知道出了什么问题。任何人都可以帮助我
答案 0 :(得分:0)
我想您需要查看Request.Form.AllKeys
才能看到发布的内容。
您的HTML输入字段应映射模型对象图的分层命名,否则模型绑定器不会将其绑定到模型。
此外,首先,在发布集合时,您可以发布隐藏的集合的起始索引(如果它不是0)。
答案 1 :(得分: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();
}