【问题标题】:How can I render a html page using spark and MVC?如何使用 spark 和 MVC 呈现 html 页面?
【发布时间】:2013-10-02 13:17:59
【问题描述】:

我正在尝试使用 Spark 和 MVC 呈现纯 html 视图,但出现以下错误:

The view 'Principal.html' or its master could not be found. The following locations were searched: 
~/Views/Site/Principal.html.aspx 
~/Views/Site/Principal.html.ascx 
~/Views/Shared/Principal.html.aspx 
~/Views/Shared/Principal.html.ascx 
Site\Principal.html.spark 
Shared\Principal.html.spark

在我的控制器中,我有:

 public ViewResult Principal()
   { 
      return View("Principal.html");
   }

我在我的 Global.asax, Start 方法中注册了 spark engina

protected override void Start()
{
    ...
    RegisterViewEngine(ViewEngines.Engines, RouteTable.Routes);
    RegisterRoutes(RouteTable.Routes);            
}

 private void RegisterViewEngine(ViewEngineCollection engines, RouteCollection routes)
 {
    SparkViewFactory engine = new SparkViewFactory();            
    RegisterFactory.DefaultRegister(IoCService.MyContainer, engine, routes);
    engines.Add(engine);
 }

如何指示要呈现的页面是 html (Principal.html) 而不是 spark 扩展?

提前致谢!

【问题讨论】:

  • 是静态html吗?如果是这样,您可以重定向到它吗?
  • 是的,它是静态 html,它是网站的初始页面。但由于我的项目配置,我需要通过控制器呈现页面......谢谢!

标签: asp.net-mvc spark-view-engine


【解决方案1】:

如果您将 Principal.html 重命名为 Principal.sparkPrincipal.html.spark 应该可以修复它。

Spark 不知道它应该寻找.html 文件进行渲染。我不建议告诉 Spark 处理所有 .html 文件,但如果你真的想要,那么你可以实现自己的 Custom IDescriptorFilterimplementation 来改变 Spark 定位视图的方式 - 但就像我说的那样,我不会推荐它 - 我宁愿将 .html 文件重命名为 .spark 您希望 Spark 获取

是否有不能重命名 html 文件扩展名的原因?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-07
    • 1970-01-01
    • 2019-01-28
    • 2018-08-04
    相关资源
    最近更新 更多