在ASP中向服务器发送对象数组时出现问题.净MVC
本文关键字:问题 MVC 数组 对象 ASP 服务器 | 更新日期: 2023-09-27 18:10:07
我正在使用ASP.NET MVC 4
的应用程序上工作。我试图发送一个对象数组到控制器。我的视图包含:
<input type="hidden" id="1" name="Persons" value='[
{"Id":1,"Name":"Abc","Description":"this is desc"},
{"Id":2,"Name":"def","Description":"this is desc"},
{"Id":4,"Name":"ghi","Description":"this is desc"}]'
/>
我的控制器动作是这样的:
public ActionResult create(List<Person> Persons)
{
//Here the Persons count is always 0, why ?
}
当我发布我的表单时,我总是得到person count 0。有谁能帮我解决这个问题吗?
尝试将输入值更改为:
{Persons: [
{"Id":1,"Name":"Abc","Description":"this is desc"},
{"Id":2,"Name":"def","Description":"this is desc"},
{"Id":4,"Name":"ghi","Description":"this is desc"}
]}