Razor.ServiceStack - Views not rendering, just def

2019-05-16 12:39发布

问题:

I've setup a site using http://razor.servicestack.net/.

I've created several views and matching services with an example as follows:

Service Example:

using ServiceStack.ServiceHost;
using ServiceStack.ServiceInterface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace website
{
    [DefaultView("AboutUs")]
    public class AboutUsService : Service
    {
        public object Get(AboutUsRequest request)
        {
            return new AboutUsResponse
            {
                //any properties that need to be set on the response object can be done inline here
            };
        }     
    }

    [Route("/About-Us")]
    public class AboutUsRequest
    {
        //any request parameters we need can be provided here.  They should be auto parsed from the request
    }

    public class AboutUsResponse
    {
        //any response properties we want to use in the view can be defined here     
    }

}

View Example (located at /Views/AboutUs.cshtml)

 @inherits ServiceStack.Razor.ViewPage<website.AboutUsResponse>
 <html><body><h1>About Us</h1></body></html>

This loads fine on windows, but fails to load on Mono/NginxFastCGI, and instead just shows the default API snapshot page:

Snapshot of AboutUsRequest generated by ServiceStack on 11/17/2012 02:30:14
view json datasource from original url: http://dev.mydomain.com:80/About-Us? in other formats: json xml csv jsv

Is there some specific change that I need to configure for this to work on the Mono/Linux side? By the way, i have IOMAP=all already turned on.

Any ideas on how to get this working would be greatly appreciated!

回答1:

Unfortunately you left out the most important part: the name and location of the Razor view.

The Snaphot page is a fallback for when ServiceStack can't find the view it's looking for, in this case since you've specified [DefaultView("AboutUs")], ServiceStack will look for a view named "AboutUs.cshtml" in the /Views/ directory, is that what you have?