Quantcast
Channel: Using Optimizely Platforms
Viewing all articles
Browse latest Browse all 8020

No parameterless constructor defined for this object. Stuck

$
0
0

Hello everyone,

so, here is my problem:

I have a controller. There are 2 action methods. One for Get and the second for Post:

Get method works just fine. Instantiates the ViewModel, passes to the view.

But I do have a problem with the Post method. Here is the signature: 

public ActionResult Index(AirRegistrationViewModel model)

The view that is supposed to send the call and ViewModel alone is simplified to bare minimum:

@model AirRegistrationViewModel

@using (Html.BeginForm("Index""AirRegistrationPage"FormMethod.Post, new { enctype = "multipart/form-data" }))              {                  @Html.AntiForgeryToken()                  <input type="submit" value="Login" />              }

On Submit click I am getting 'No parameterless constructor defined for this object'.

As far as I understand the call to the post method does not send over the ViewModel, but supposed to. And MVC tries to instantiate it.
While instantiating it looks at the constructor for the ViewModel:

public AirRegistrationViewModel(AirRegistrationPage airRegistrationPage) : base(airRegistrationPage)      {          ShowRegistrationForm = true;      }

can't get resolve AirRegistrationPage, and looks for parameterless constructor, can't find it, hence the error displayed... :(

If my logic is correct, then the question I have.. why? why the call from the view form does not send alone the ViewModel that has been intantiated on the previos call
to display that view?

thank you for any help.

Alex


 

Viewing all articles
Browse latest Browse all 8020

Trending Articles