HttpPost on ASP.Net MVC3 - "Without the parametric constructor defined for this object"

Possible duplicate:
ASP.NET MVC: no parameterless constructor defined for this object

I am working on an ASP.NET MVC3 application.

I am trying to use [HttpPost] to retrieve information when a user enters it into a form.

Based on what I am doing with empty ASP.NET Project scripts by default, I have the following:

In my controller:

  public ActionResult Ticket(int id) { Models.Ticket model = new Models.Ticket(id); return View("Ticket", model); } [HttpPost] public ActionResult Ticket(int id, MMCR.Models.Ticket model) { if (id != model.TicketNo) { return View("Error"); } return View("Ticket", model); } 

And in the view, I have:

 @using (Html.BeginForm()) { <div> <fieldset> <legend>View Ticket Details</legend> <div class="editor-label"> @Html.LabelFor(m=>m.Status) </div> <div class="editor-field"> @Html.DropDownListFor(m=>m.Status, Model.Status) </div> <p> <input type="submit" value="Update" /> </p> </fieldset> </div> } 

(obviously dropping repetitive things).

However, when I click on the button, I get an error message:

Exception Details: System.MissingMethodException: A constructor without parameters was not defined for this object.

Can someone give some advice on how to resolve this?

+6
source share
1 answer

Your MMCR.Models.Ticket class needs a constructor without parameters.

When you pass an object of this type through the Post method, MVC will instantiate the class using the parameterless constructor. Then it will match the form fields with this object.

+16
source

Source: https://habr.com/ru/post/911611/


All Articles