Possible Duplicate:
ASP.NET MVC: No parameterless constructor defined for this object
I'm working on an ASP.NET MVC3 application.
I'm trying to use the [HttpPost]
to retrieve information when a user enters it on a form.
Basing what I do off the "default" blank ASP.Net project's Logon scripts, 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 snipping out repetetive stuff).
However, when I click on the button I get an error:
Exception Details: System.MissingMethodException: No parameterless constructor defined for this object.
Can anyone give some advice on how to resolve this?
Your class MMCR.Models.Ticket
needs a parameterless constructor.
When you pass an object of this type through the Post method, MVC will create an instance of the class using a parameterless constructor. It will then map the form fields to that object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With