bindingContext.Model

Jan 9, 2010 at 1:06 PM
Edited Jan 9, 2010 at 1:06 PM

I have been trying to get your sourcecode up and running but i am experiencing a difficulty for which i cannot figure out the solution.
In the DynamicFormModelBinder, the bindingContext.Model is always returning a null value, thus, it cannot traverse the fields that were setup previously within the dynamic form.

Any clue what could cause this behaviour?

Regards,
avsomeren

Coordinator
Jan 31, 2010 at 11:29 PM

Sorry for the slow response. I have just released a new version of the library that you should try out.

Are you trying to accept the Form object as an action method parameter?

This doesn't work in the old release. In the old release, you needed to manually model bind the Form by calling UpdateModel(myForm) or TryUpdateModel(myForm) somewhere in the body of your action method. This means that you would have to manually hang on to the Form object graph across requests somehow. Here is an example:

 

public ActionResult FormPosted()
{
    var form = (DynamicForm)Session["dynForm"];
    UpdateModel(form);

    if(form.Validate())
    {
        // the form is valid
        // do something
    }

    // the form is invalid
    return View();
}

In the new release, you can set the Form.Serialize property to true and then just accept the form as an action method parameter like this:

public ActionResult FormPosted(Form form)
{
    if(form.Validate())
    {
        // the form is valid
        // do something
    }

    // the form is invalid
    return View();
}

Hope this helps. Check out the new release. It includes a demo application that should clear up any problems that you have.