this is the second time this has happened to me now, and I have no idea what is going on. I have a MVC view that is strongly typed and being fed in the model by the controller using :
public ActionResult EditSubscription (String subName){
DutiesWeb.Models.EditSubscriptionViewModel mod = new Models.EditSubscriptionViewModel(subName);
return View("EditSubscription", mod);
}
everything then displays fine on the edit page:
@model DutiesWeb.Models.EditSubscriptionViewModel
@{
ViewBag.Title = "EditSubscription";
}
<h2>EditSubscription</h2>
@using (Html.BeginForm("EditSubscriptionSubmitAction","Home", FormMethod.Post )) {
<div class="form-horizontal">
<div class="form-group">
<div class="col-lg-12">
</div>
</div>
<div class="form-group">
<div class="col-lg-2">
@Html.LabelFor(model => model.subscription.subscriptionName, new { @class = "control-label" })
</div>
<div class="col-lg-10">
@Html.TextBoxFor(model => model.subscription.subscriptionName, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
<div class="col-lg-2">
@Html.LabelFor(model => model.subscription.messageCount, new { @class = "control-label" })
</div>
<div class="col-lg-10">
@Html.TextBoxFor(model => model.subscription.messageCount, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
<div class="col-lg-2">
@Html.LabelFor(model => model.subscription.lastAccessed, new { @class = "control-label" })
</div>
<div class="col-lg-10">
@Html.TextBoxFor(model => model.subscription.lastAccessed, new { @class = "form-control" })
</div>
</div>
<div class="form-group">
<div class="col-md-2">
@Html.LabelFor(model => model.subscription.status, new { @class = "control-label" })
</div>
<div class="col-md-10">
@Html.DropDownListFor(model => model.subscription.status,
(IEnumerable<SelectListItem>)Model.subscriptionActiveOptions,
"Please Select ...", new { @class = "form-control", @id = "ddlSubscriptionActive" })
@Html.ValidationMessageFor(model => model.subscription.status)
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<input type="submit" value="Save Changes" class="btn btn-primary" />
<input type="button" value="Delete" class="btn btn-danger" />
</div>
</div>
</div>} <!--Yes, I have remembered the closing bracket-->
But, whenever I try and submit the form using the 'Save Changes' button (or any other submit button I put on the page), I get one of those nasty IIS white-and-yellow errors stating :
No parameterless constructor defined for this object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.MissingMethodException: No parameterless constructor defined for this object.
Its almost as if the View has forgotten it has been given a model, as it's obviously looking to invoke a method in the controller with the signature
public ActionResult EditSubscriptionSubmitAction(){}
rather than
public ActionResult EditSubscriptionSubmitAction (DutiesWeb.Models.EditSubscriptionViewModel model) {}
and I have no idea why. Anyone have any ideas?