Ajax Post: ASP.NET MVC action is receiving empty object

后端 未结 1 1414
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-23 05:26

I have this form:

@model CupCakeUI.Models.CupCakeEditViewModel
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = \"createFrm\" }))
{
    
相关标签:
1条回答
  • 2021-01-23 05:58

    You model contains only fields, and the DefaultModelBinder does not bind fields, only properties. Change the model to

    public class CupCakeEditViewModel
    {
        public int CupCakeId { get; set; }
        [Display(Name = "CupCake Name")]
        public string Name { get; set; }
        public string Price { get; set; }
    }
    
    0 讨论(0)
提交回复
热议问题