Hello,
When I submit a Create form the model is always considered invalid.
However if I change the Id from Int32 to Int32? it works fine ... Any idea why?
Do all my models need to have the Id as nullable? This is really strange ...
Here is my view model code (it is working because Id is nullable):
public class ArticleFormViewModel : PageViewModel {
public Int32 Id { get; set; }
public String Content { get; set; }
public String Title { get; set; }
} // ArticleFormViewModel
The action:
[AcceptVerbs(HttpVerbs.Post), ValidateAntiForgeryToken, ValidateInput(false)]
public ActionResult Create(ArticleFormViewModel model) {
if (ModelState.IsValid) {
articleRepository.Create(Mapper.Map<ArticleFormViewModel, Article>(model));
session.Commit();
return RedirectToAction("List");
} else {
return View(model);
}
} // Create
And in the view I have the following:
<%Html.BeginForm("Create", "Article", FormMethod.Post, new { @class = "Horizontal" });%>
<%Html.RenderPartial("Form");%>
<%=Html.SubmitButton("Submit", "Submit", new { @class = "Submit" })%>
<%=Html.AntiForgeryToken()%>
</div>
Thanks,
Miguel