NancyFX: How to check if the request / form string values ​​are passed correctly to my handler?

Nancy passes my query string and forms the values ​​to my handlers using a variable dynamic. The following example shows the form values ​​passed to the POST handler through a Nancy request, for example. Request.Form.xxx.

Handler

Post["/"] = _ =>
    {
        var userId = (string) Request.Form.userid;
        if (userId.IsEmpty()) return HttpStatusCode.UnprocessableEntity;
        return HttpStatusCode.OK;
    };

You can see what I am inserting useridinto the string, and then using the string extension method to check if the value is empty or empty string (equivalent string.IsNullOrEmpty()).

I would prefer to use the extension method for the dynamic type so that I can perform my health checks before doing anything else. I need a code:

if(Request.Form.userid.IsEmpty()) return HttpStatusCode.UnprocessableEntity;

dynamic. , . DLR.

, , / Nancy?

+5
2
Request.Form.userid.HasValue

DynamicDictionary, ,

+12

Bind i.e ModelBinder, , HTML.

var course = this.Bind<Course>(); // Course is our model class 
if(course != null) {
    // your codes go here
} 
+2

All Articles