ASP.NET MVC View Not posting back to Post method and expecting a parameterless Constructor?

Posted by VJ on Stack Overflow See other posts from Stack Overflow or by VJ
Published on 2010-05-12T17:05:54Z Indexed on 2010/05/12 17:44 UTC
Read the original article Hit count: 199

Filed under:
|

Hi, I am trying to post back some data using a viewmodel i have created and it works for me for one of the projects.But I am doin this right now

public ActionResult Foo(string userkey)
  {
    vm.Value="Xvalue";
    return View(vm);
  }

  [HttpPost]
  public ActionResult  Foo( MyViewModel vm)
  {
    // process input
    if (inputOK)
      string value=vm.Value
      return RedirectToAction("Index");
    return View();
  }
public class MyViewModel
{
public string Value { get; set; }
public SomeClass newobj {get;set;}

}
public class SomeClass
{
   public int id{get;set;}
   public string str{get;set;}
}

So it on debugging never goes into the parameter method for Post although on the view i have added a form and a button that submits and the page inherits from the viewmodel.I get an error saying it expects a parameterless constructor how do I fix this ? . I wrote an post method with no parameters and it does go into that method

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about views