我正在努力ServiceStack.Razor
工作,但我得到了一个IndexOutOfRangeException
. 堆栈跟踪如下所示:
at ServiceStack.Text.Jsv.JsvTypeSerializer.EatMapKey(String value, Int32& i)
at ServiceStack.Text.Common.DeserializeDictionary`1.ParseStringDictionary(String value)
at ServiceStack.Html.ViewDataDictionary.PopulateModelState()
at ServiceStack.Razor.ViewPage`1.Init(IRazorViewEngine viewEngine, ViewDataDictionary viewData, IHttpRequest httpReq, IHttpResponse httpRes)
at ServiceStack.Razor.Templating.TemplateService.InitTemplate[T](T model, ITemplate instance, IHttpRequest httpReq, IHttpResponse httpRes)
at ServiceStack.Razor.Templating.TemplateService.ExecuteTemplate[T](T model, String name, String defaultTemplatePath, IHttpRequest httpReq, IHttpResponse httpRes)
at ServiceStack.Razor.RazorFormat.ProcessRazorPage(IHttpRequest httpReq, ViewPageRef razorPage, Object dto, IHttpResponse httpRes)
at ServiceStack.Razor.RazorFormat.ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, Object dto)
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
at ServiceStack.WebHost.Endpoints.Formats.HtmlFormat.SerializeToStream(IRequestContext requestContext, Object response, IHttpResponse httpRes)
at ServiceStack.WebHost.Endpoints.Extensions.HttpResponseExtensions.WriteToResponse(IHttpResponse response, Object result, ResponseSerializerDelegate defaultAction, IRequestContext serializerCtx, Byte[] bodyPrefix, Byte[] bodySuffix)
设置
Error.cs
public class Error
{
public int TrackingNumber { get; set; }
public string ClientName { get; set; }
}
[Route("/Errors", "GET")]
[Authenticate]
public class Errors : List<Error>
{
}
service.cs
public class ErrorService : Service
{
public object Get(Errors request)
{
var fakeError = new Error(){ TrackingNumber=1, ClientName="Test"};
var fakeErrorList = new Errors();
fakeErrorList.Add(fakeError);
return fakeErrorList;
}
}
errors.cshtml
@inherits ViewPage<Errors>
<div>
@Model.Count
</div>