从View到Controller的POST时模型始终为NULL

时间:2019-04-27 06:21:31

标签: c# asp.net-mvc asp.net-core

我的控制器中有此代码

public describeAutoScalingGroups() {
        const data = (): AWS.AutoScaling.Types.AutoScalingGroupsType => {


            return {
                // some values here
        };

        return {
            promise: data
        };
    }

这是模特

        public IActionResult Create()
        {
            return View(new Partner());
        }

        [HttpPost]
        //[ValidateAntiForgeryToken]
        public IActionResult Create(Partner model, IFormCollection pForm)
        {
            _uow.Partner.Insert(model);

            return View("List");
        }

这是视图

public class Partner
{
    public Guid ID;
    public string Type;
    public string Code;
    public string Name;
    public string IDCard;
    public DateTime BirthDate;
    public bool CardStatus;
    public string Address;
    public string Email;
}

HTTPOST将不会自动绑定模型并始终返回NULL,我检查了FormCollection,它似乎具有所有正确的值,我在做什么错了?

1 个答案:

答案 0 :(得分:1)

模型中的属性应定义为自动属性。

public class Partner
{
    public Guid ID {get; set;}
    public string Type {get; set;}
    public string Code {get; set;}
    public string Name {get; set;}
    public string IDCard {get; set;}
    public DateTime BirthDate {get; set;}
    public bool CardStatus {get; set;}
    public string Address {get; set;}
    public string Email {get; set;}
}