2010-01-14 64 views
5

你如何修改ASP.NET MVC 2.0项目,星火视图引擎工作?火花视图引擎使用ASP.NET MVC2

我试着喜欢这里描述: http://dotnetslackers.com/articles/aspnet/installing-the-spark-view-engine-into-asp-net-mvc-2-preview-2.aspx

但不知何故,它仍然会尝试路由到.aspx文件。

这里我的Global.asax的代码:

public class MvcApplication : System.Web.HttpApplication 
{ 
    public static void RegisterRoutes(RouteCollection routes) 
    { 
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

     routes.MapRoute(
      "Default",            // Route name 
      "{controller}/{action}/{id}",       // URL with parameters 
      new { controller = "Home", action = "Index", id = "" } // Parameter defaults 
     ); 

    } 

    protected void Application_Start() 
    { 
     SparkViewFactory svf = new SparkViewFactory(); 
     PrecompileViews(svf); 

     AreaRegistration.RegisterAllAreas(); 

     RegisterRoutes(RouteTable.Routes); 
    } 

    public static void PrecompileViews(SparkViewFactory svf) 
    { 
     var controllerFactory = svf; 
     var viewFactory = new SparkViewFactory(controllerFactory.Settings); 
     var batch = new SparkBatchDescriptor(); 
     batch 
      .For<HomeController>() 
      .For<AccountController>(); 
     viewFactory.Precompile(batch); 
    } 
} 

}

+0

看起来没有人为此问题提供解决方案,让我们等待发布:( – Sasha 2010-01-20 07:21:54

+0

这在ASP.NET MVC 2的最新版本中暂时中断。请参阅http://stackoverflow.com/questions/2138583/cant-set 。-up-ASP净MVC-2,RC-和火花视图引擎,你可以在此期间使用一种变通方法 – Eilon 2010-02-01 04:58:38

回答

3

http://www.simple-talk.com/community/blogs/asiemer/archive/2010/01/31/89132.aspx

我不得不下载火花视图引擎源代码(http://sparkviewengine.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=27600)。一旦我这样做了,我浏览了每个引用1.0版本System.Web.Mvc程序集的项目,并更新为指向System.Web.Mvc 2.0。从那里你可以建立解决方案(在Visual Studio中),你会发现一大堆测试开始失败。您可以尝试修复它们(通过添加您现在需要的其他TextWriter参数)。您还会看到SparkView.cs文件抱怨缺少参数。在Render方法(源代码,我下载的行100),我不得不更新wrappedViewContext的实例,看起来像这样(加作家的参数列表的末尾):

public void Render(ViewContext viewContext, TextWriter writer) 
{ 
    var wrappedHttpContext = new HttpContextWrapper(viewContext.HttpContext, this); 

    var wrappedViewContext = new ViewContext(
     new ControllerContext(wrappedHttpContext, viewContext.RouteData, viewContext.Controller), 
     viewContext.View, 
     viewContext.ViewData, 
     viewContext.TempData, 
     writer); // <-- add the writer to the end of the list of parameters 

    ... 
} 

一旦代码已更新,您可以运行位于所下载源的根目录下的build.cmd脚本。构建过程将在build/dist文件夹中创建一个zip文件。采取这些新的DLL,并将其添加到您的网站。事情应该再次运作。

+0

感谢。 创建它的书很棒。 – Ben 2010-02-01 15:36:19

2

您需要注册的视图引擎:

ViewEngines.Engines.Add(new SparkViewFactory()); 
+0

嗯,我已经尝试过了:没有发现 方法:“太虚系统。 Web.Mvc.ViewContext..ctor(System.Web.Mvc.ControllerContext,System.Web.Mvc.IView,System.Web.Mvc.ViewDataDictionary,System.Web.Mvc.TempDataDictionary)”。 – Ben 2010-01-14 15:31:49

+0

@ben这仅仅是破暂时的,SparkViewEngine的作者正在修复这个问题,但是他现在有点忙。 – Eilon 2010-02-01 04:57:38

0

我的global.asax.cs包含此:

public class MvcApplication : System.Web.HttpApplication 
{ 
    public static void RegisterRoutes(RouteCollection routes) 
    { 
     routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

     routes.MapRoute(
      "Default",            // Route name 
      "{controller}/{action}/{id}",       // URL with parameters 
      new { controller = "Home", action = "Index", id = "" } // Parameter defaults 
     ); 

    } 

    protected void Application_Start() 
    { 
     RegisterRoutes(RouteTable.Routes); 
     ViewEngines.Engines.Add(new SparkViewFactory()); 

    } 
} 

和我的web.config包含此:

<configSections> 
    <section name="spark" type="Spark.Configuration.SparkSectionHandler, Spark"/> 
    <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
     <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
      <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> 
      <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"> 
       <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/> 
       <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> 
       <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> 
       <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/> 
      </sectionGroup> 
     </sectionGroup> 
    </sectionGroup> 
</configSections> 

<spark> 

    <pages> 
     <namespaces> 
      <add namespace="System"/> 
      <add namespace="System.Collections.Generic"/> 
      <add namespace="System.Linq"/> 
      <add namespace="System.Web.Mvc"/> 
     </namespaces> 
    </pages> 
</spark> 
+0

嗯,我试过了。它导致:未找到方法:'Void System.Web.Mvc.ViewContext..ctor(System.Web.Mvc.ControllerContext,System.Web.Mvc.IView,System.Web.Mvc.ViewDataDictionary,System.Web.Mvc .TempDataDictionary)”。 – Ben 2010-01-14 15:34:55

+0

我正在使用MVC2,或许它与MVC1不同。 – RedFilter 2010-01-14 15:40:04

+0

我使用MVC2太:-( – Ben 2010-01-14 15:41:47

0

我想看看带有Spark-1.0.zip包的示例。看着他们的一个随机有这样的Global.asax.cs中

SparkEngineStarter.RegisterViewEngine(); 

希望它能帮助。

1

如果你喜欢滚动自己再有就是对sparkview google group修复。

个人而言,我会等待下一个版本。