Search This Blog

Saturday 1 April 2017

ViewModel returns null on postback mvc 4

Make sure controller action method parameter object name not match with any its property.

This is model
public class QuestionModel
{
      [Required]
      public string Question getset; }
}

This is Controller Action method
[HttpPost]
public ActionResult Create(QuestionModel Question)
{
      //Add your code here
}

Create method parameter 
QuestionModel Question object name matching with its property Question.
In this case when we post data from view to controller ViewModel returns null.

No comments:

Post a Comment