I've tried solutions from threads:
- ASP.Net MVC How to pass data from view to controller
- Passing Model to Controller from View in ASP.NET MVC
- MVC4 Passing model from view to controller
but there is still no solution for my problem. My code seems to be fine
the view (DodajWpis):
@model mvc.Models.WpisModel
....
@using (Html.BeginForm("AddedNew", "Home", FormMethod.Post))
{
@Html.Label("Title")
@Html.EditorFor(x => x.title)
@Html.Label("Description")
@Html.EditorFor(x => x.descr)
@Html.Label("Priority")
@Html.EditorFor(x => x.priority)
@Html.Label("Deadline")
@Html.EditorFor(x => x.deadline)
<input type="submit" />
}
controller:
[HttpGet]
public ActionResult AddNew()
{
WpisModel wpis = new WpisModel();
return View("DodajWpis",wpis);
}
[HttpPost]
public ActionResult AddedNew(WpisModel model)
{
return null;
}
and model
public class WpisModel
{
[Required(ErrorMessage = "required")]
public string descr;
[Required(ErrorMessage = "required")]
public string title;
[Required(ErrorMessage = "required")]
public int priority;
[Required(ErrorMessage = "required")]
[DataType(DataType.Date)]
public DateTime deadline;
}
I'm receiving an empty model from my view. I also tried to bind it (via this article, "Registering Model Binders" section) but i can't add code "Bind(Allowed= " and i'm stuck at it. Can someone take a look and help me with that?
Thanks.
DefaultModelBinderdoes not bind fields. You need to make them properties (add{ get; set; }so their values can be set