這裏是我的控制器:ASP.NET DefaultModelBinder沒有約束力JSON對象集合
public class TagsController : Controller
{
public ActionResult Attach(TagsAttach model)
{
// ...
}
}
這裏是我的看法,型號:
public class TagsAttach
{
public int GroupID { get; set; }
public List<Tag> Tags { get; set; }
}
public class Tag
{
public int ID { get; set; }
}
而這裏的,我使用的Javascript代碼試圖提交我的數據:
var data = {
GroupID: 12,
Tags: []
};
data.Tags.push({ ID: 3 });
data.Tags.push({ ID: 4 });
$.push('/Tags/Attach', data);
但是,當我調試我的控制器動作時,我發現一切都在那裏exc ept獲取每個Tag對象中的ID值。
因此,我的 '模式' 參數如下:
model
GroupID 12
Tags
Tag
ID 0
Tag
ID 0
這是爲什麼?我必須爲ASP.NET MVC做些什麼來正確綁定我的ID值?
(注:?我在做什麼,似乎幾乎完全一樣this那麼,爲什麼不是爲我工作)