【发布时间】:2014-05-25 01:42:46
【问题描述】:
有没有人在使用 System.Web.Optimization 和 Nancy Self Hosting 时运气好? 如果我注释掉 "Styles.Render("~/csspack/logincss").ToString()" 视图工作正常。 如果我将其留在空白页面中,则会发送到浏览器。
这就是我的 Razor 配置的样子。
public class RazorConfig : IRazorConfiguration
{
public IEnumerable<string> GetAssemblyNames()
{
yield return "Microsoft.Web.Infrastructure";
yield return "WebGrease";
yield return "System.Web.Optimization";
yield return "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a";
}
public IEnumerable<string> GetDefaultNamespaces()
{
yield return "Microsoft.Web.Infrastructure";
yield return "WebGrease";
yield return "System";
yield return "System.Web";
yield return "System.Web.Optimization";
yield return "Nancy.ViewEngines.Razor";
}
public bool AutoIncludeModelNamespace
{
get { return false; }
}
}
我是这样在启动时注册的。
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
{
container.Register<IRazorConfiguration, RazorConfig>().AsSingleton();
container.Register<RazorViewEngine>();
.....bundle code...
}
这是我的看法。
inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<dynamic>
@using Nancy.Helpers
@using System.Web.Optimization
<!DOCTYPE html>
<html lang="en">
<head>
<head>
<meta charset="utf-8" />
<title>Log In</title>
@Html.Raw(Styles.Render("~/csspack/logincss").ToString())
</head>
.... more html ....
【问题讨论】:
-
不应该只是
@Styles.Render("~/csspack/logincss")没有@Html.Raw或ToString()吗? -
您遗漏了最重要的信息 - 您得到的错误
-
@ArtyomNeustroev 如果你在 Asp.net 工作,是的,但在 Nancy 你必须添加。
-
@TheCodeJunkie 我添加了我的错误或缺少。
-
@DonnyV。我有同样的问题,有没有找到解决方案的运气?