我在将复杂类型传递给控制器时遇到问题。
这是我的模型的样子:
public class Party
{
    [XmlAttribute]
    public int RsvpCode { get; set; }
    public List<Guest> Guests { get; set; }
    public string Comments { get; set; }
}
public class Guest
{
    [XmlAttribute]
    public string Name { get; set; }
    [XmlAttribute]
    public int MealOption { get; set; }
    [XmlAttribute]
    public bool Attending { get; set; }
}
我的控制器方法如下所示:
    public JsonResult Submit(Party party)
    {
        return Json(party);
    }
我正在尝试像这样进行我的 ajax 调用:
var party = { RsvpCode: 1, Guests: [{ Name: "test asdfasdf", MealOption: 1, Attending: true }, { Name: "test asdfasdf", MealOption: 1, Attending: true}] };
                $.getJSON("/Rsvp/Submit", party, function(response) {
                    alert(response);
                });
出了点问题,但我不确定是什么。我在警报声明中收到任何返回给我的东西。有任何想法吗?
我还尝试查看提交到控制器方法中的值,但它看起来不正确。我在 ajax 调用中的某处丢失了信息。
我也试过这样创建我的派对对象,但它没有用:
var party = { "RsvpCode": 1, "Guests": [{ "Name": "test asdfasdf", "MealOption": 1, "Attending": true }, { "Name": "test asdfasdf", "MealOption": 1, "Attending": true}], "Comments": "testdsfsdf" };