Why is my Nancyfx Negotiator not returning the correct models?

140 Views Asked by At

I have the following route defined:

Get["/test"] = _ => Negotiate
    .WithModel(new { Name = "This is base model " })
    .WithMediaRangeModel(new MediaRange("text/html"), new { Name = "This is text/html" })
    .WithMediaRangeModel(new MediaRange("text/plain"), new { Name = "This is text/plain" })
    .WithView("index");

What I am getting:

Accepts header            Actual response (content-type + model)
-----------------         -----------------------------------------
text/html            (OK) HTML view with "html" model 
application/json     (OK) application/json with "base" model
text/plain                HTTP 406 
text/*                    application/json with "html" model 
*/*                       application/json with "html" model 

So:

  • How do I get the "text/plain" model to come back with Accepts: text/plain?
  • Why is the "html" model (with a content type of application/json) being returned for */*??

I really just want one model for JSON (or any other format), and a different model when an HTML view is rendered (including PageTitle and some other HTML-specific things).

This feels very much like a bug to me, but since I'm new to NancyFx and it's been around for a while I'll assume that I'm doing something wrong.

I'm using Nancy 1.4.3 with Nancy.Hosting.Self 1.4.1.

0

There are 0 best solutions below