null reference servicestack viewpage

时间:2013-11-28 05:44:52

标签: c# asp.net-mvc-4 servicestack

我已经开始构建一个基于服务堆栈的无控制MVC应用程序,它使用'RazorFormat'。我已成功构建了几个页面。这些页面只是映射到返回简单单个Document对象的服务。这一切都很好。我已经构建了另一个视图,当我访问特定路由时应返回该视图。此服务返回IEnumerable。我能够单步执行代码以查看我的服务是否正确返回但视图从不呈现,我看到NullReferenceException。在调试期间,我能够看到抛出的操作名称是ResourceTemplateRequest和堆栈跟踪:

  

错误CodeNullReferenceException MessageObject引用未设置为   对象的实例。在ASP .___ Layout.Execute()处的堆栈跟踪   ServiceStack.Razor.ViewPage 1.WriteTo(StreamWriter writer) at ServiceStack.Razor.Managers.RazorPageResolver.ExecuteRazorPageWithLayout(IHttpRequest httpReq, IHttpResponse httpRes, Object model, IRazorView page, Func 1   布局)   ServiceStack.Razor.Managers.RazorPageResolver.ExecuteRazorPageWithLayout(IHttpRequest   httpReq,IHttpResponse httpRes,对象模型,IRazorView页面,Func 1 layout) at ServiceStack.Razor.Managers.RazorPageResolver.ResolveAndExecuteRazorPage(IHttpRequest httpReq, IHttpResponse httpRes, Object model, RazorPage razorPage) at ServiceStack.Razor.Managers.RazorPageResolver.ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, Object dto) at ServiceStack.WebHost.Endpoints.Formats.HtmlFormat.<>c__DisplayClass1.<SerializeToStream>b__0(IViewEngine x) at System.Linq.Enumerable.Any[TSource](IEnumerable 1源,Func`2   谓词)   ServiceStack.WebHost.Endpoints.Formats.HtmlFormat.SerializeToStream(IRequestContext   requestContext,Object response,IHttpResponse httpRes)at   ServiceStack.WebHost.Endpoints.Extensions.HttpResponseExtensions.WriteToResponse(IHttpResponse   响应,对象结果,ResponseSerializerDelegate defaultAction,   IRequestContext serializerCtx,Byte [] bodyPrefix,Byte [] bodySuffix)

但我无法弄清楚如何解决它。我的服务使用[DefaultView("ResourceTemplate")]属性进行修饰。有什么想法吗?

即使我在视图中评论所有内容,我也会得到例外。这是一些代码

服务

[Authenticate]
public class ResourceTemplateService : Service
{
    [DefaultView("ResourceTemplate")]
    public ResourceTemplateResponse Get(ResourceTemplateRequest request)
    {
        var filter = factory.SetUp()
             .WithTopN(Paging.GetTopN(request))
             .WithGlobalPath(request.NodeAliasPath.StripChannel())
             .Value;

        var documents = repository.GetDocumentsByPath(filter).ToList();
        var currentDocument = repository.GetDocumentByNodeAliasPath(request.NodeAliasPath);
        var page = Paging.GetPage(documents, request);

        if (documents.None())
            throw HttpError.NotFound(string.Format("No children found for path {0}", request.NodeAliasPath));

        return new ResourceTemplateResponse
        {
            Count = documents.Count(),
            CurrentDocument = currentDocument,
            Documents = page,
            CurrentNodeAliasPath = request.NodeAliasPath
        };
    }
}


Request


[Route("/resource/{NodeAliasPath*}")]
public class ResourceTemplateRequest : DocumentCollectionRequest, IReturn<ResourceTemplateResponse>
{
    public ResourceTemplateRequest()
    {
        View = "ResourceTemplate";
        //Set base call properties
    }
}


View

@using Zoo.Optus.YesCentral.Mobile.Model
@using Zoo.Optus.YesCentral.Web.Factories
@inherits ServiceStack.Razor.ViewPage<ResourceTemplateResponse>

@{
 Layout = "_Layout";

 ActivityFactory.LogPageVisit(Model.CurrentDocument.DocumentName, Model.CurrentDocument.NodeId, true);
 }


@foreach (var document in @Model.Documents)
{
@document.DocumentName.ToMvcHtmlString()
}

0 个答案:

没有答案