Model is null while submitting the form in partial view in MVC5

后端 未结 2 1462
醉梦人生
醉梦人生 2021-01-25 16:51

I am just trying to learn MVC and facing some issues.When I am submitting my partial view, I am getting null in Model Blog inside Create Method.

What I

相关标签:
2条回答
  • 2021-01-25 17:37

    Your class Blog only contains fields, not properties so the DefaultModelBinder cannot set their values. Change it add getters/setters

    public class Blog
    {
        public string Name { get; set; }
        public string URL { get; set; }
    }
    
    0 讨论(0)
  • 2021-01-25 17:46

    Maybe this answer relates to your question: Is there a reason why the default modelbinder doesn't bind to fields?

    Pay attention at DefaultModelBinder, ModelBinderContext, ModelMetadata. This explains it all.

    0 讨论(0)
提交回复
热议问题