Custom ViewModel with MVC 2 Strongly Typed HTML Helpers return null object on Create?

后端 未结 3 1744
清酒与你
清酒与你 2021-01-06 10:52

I am having a trouble while trying to create an entity with a custom view modeled create form. Below is my custom view model for Category Creation form.

publ         


        
3条回答
  •  攒了一身酷
    2021-01-06 11:44

    Make a default constructor for your viewmodel and initialize the Category there

    public CategoryFormViewModel() 
    { 
        Category = new Category()
    }
    

    And at your controller action receive the viewmodel

    public ActionResult ActionName(CategoryFormViewModel model)
    {
        //here you can access model.Category.Title
    }
    

提交回复
热议问题