本文整理汇总了C#中Nancy.Responses.Negotiation.Negotiator.WithModel方法的典型用法代码示例。如果您正苦于以下问题:C# Negotiator.WithModel方法的具体用法?C# Negotiator.WithModel怎么用?C# Negotiator.WithModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nancy.Responses.Negotiation.Negotiator
的用法示例。
在下文中一共展示了Negotiator.WithModel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Handle
public void Handle(HttpStatusCode statusCode, NancyContext context)
{
var response = new Negotiator(context);
Error error = null;
if (context.Items.ContainsKey("OnErrorException"))
{
var exception = context.Items["OnErrorException"] as Exception;
error = new Error { ErrorMessage = exception.Message, FullException = exception.ToString() };
}
response.WithModel(new ErrorPageViewModel
{
Title = "Sorry, something went wrong",
Summary = error == null ? "An unexpected error occurred." : error.ErrorMessage,
Details = error == null ? null : error.FullException // TODO: Obey "ShowFullErrors" flag in config
}).WithStatusCode(statusCode).WithView("Error");
var errorresponse = responseNegotiator.NegotiateResponse(response, context);
string s = "";
context.Response = errorresponse;
}
示例2: GetNegotiator
private static Negotiator GetNegotiator(object routeResult, NancyContext context)
{
var negotiator = routeResult as Negotiator;
if (negotiator == null)
{
context.WriteTraceLog(sb => sb.AppendFormat("[DefaultRouteInvoker] Wrapping result of type {0} in negotiator\n", routeResult.GetType()));
negotiator = new Negotiator(context);
negotiator.WithModel(routeResult);
}
return negotiator;
}