2

I've tried solutions from threads:

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.

2
  • 4
    The DefaultModelBinder does not bind fields. You need to make them properties (add { get; set; } so their values can be set Commented Sep 4, 2016 at 12:51
  • you're right. thank you Commented Sep 4, 2016 at 13:36

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.