Search code examples
nancy

How to bind form to model in NancyFX


I'm new to NancyFX and trying to simply bind a posted form to my model.

In the module when trying to access the posted values I run following statement:

        string email = this.Context.Request.Form["Email"];
        Debug.WriteLine(email);

Result is: "Nancy.DynamicDictionaryValue" instead of posted value

Can anybody tell me what newbie mistake I'm doing:

The form looks like:

<form method="post" action="account">
    <input type="text" id="Email" />
    <input type="password" id="Password" />
    <input type="submit" value="Create" />
</form>

the routing in Module contructor:

       Post["/"] = parameters => CreateAccount(parameters);

Solution

  • The dynamic dictionary returns a dynamic value, if you cast it to a string (implicitly or explicitly) you'll get what you want, or just use the build in model binder https://github.com/NancyFx/Nancy/wiki/Model-binding