Why does the model binder need an empty constructor

前端 未结 4 1688
闹比i
闹比i 2020-12-21 05:21

I need some help with some fundamentals here...

I have this controller that serves up my view with an instance of a class (at least that\'s how I think it works). So

4条回答
  •  难免孤独
    2020-12-21 05:47

    I am a little confused by the question but instead have you tried this:

    [HttpPost] 
    public ActionResult Index(MyModel foo){
      if(foo.someString == "laaaa")
        return RedirctToAction("End", "EndCntrl", foo);
      else
        throw new Exception();
    }
    

    You only need a parameterless constructor if you added a parameterized constructor.

    Ex: MyObject item = new MyObject();

提交回复
热议问题