Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spark-View-Engine with ASP.NET MVC2

How do you modify a ASP.NET MVC 2.0 project to work with the Spark View Engine?

I tried like described here: http://dotnetslackers.com/articles/aspnet/installing-the-spark-view-engine-into-asp-net-mvc-2-preview-2.aspx

But somehow it still tries to route to .aspx files.

Here the code of my 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);
    }
}

}

like image 554
Ben Avatar asked Jan 14 '10 15:01

Ben


People also ask

What are the 2 popular ASP.NET MVC view engines?

At this point there are two engines inside of the view engine collection: the Web forms view engine (the default ASP.NET MVC view engine) and the Spark View Engine.

What is ASP Net mvc3?

ASP.NET MVC 3 is a framework for developing highly testable and maintainable Web applications by leveraging the Model-View-Controller (MVC) pattern.

Is spark a MVC?

Spark is a view engine for ASP.NET MVC and Castle Project MonoRail frameworks. The idea is to allow the html to dominate the flow and any code to fit seamlessly.

What is mvc4?

ASP.NET MVC 4 is a framework for building scalable, standards-based web applications using well-established design patterns and the power of the ASP.NET and the . NET framework. This new, fourth version of the framework focuses on making mobile web application development easier.


1 Answers

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

I had to download the spark view engine source code (http://sparkviewengine.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=27600). Once I did that I went through each of the projects that had a reference to the 1.0 version of System.Web.Mvc assembly and updated to reference to point to System.Web.Mvc 2.0. From there you can build the solution (in visual studio) and you will find that a whole bunch of tests start to fail. You can attempt to fix them (by adding the additional TextWriter parameter you will find is now needed). You will also see that the SparkView.cs file complains about a missing parameter. In the Render method (line 100 of the source code I downloaded) I had to update the instantiation of the wrappedViewContext to look like this (add writer to the end of the list of parameters):

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

    ...
}

Once the code is updated you can run the build.cmd script that is in the root of the source you downloaded. The build process will create a zip file in the build/dist folder. Take those new dll's and add them to your website. Things should work once again.

like image 128
Andrew Siemer Avatar answered Oct 31 '22 14:10

Andrew Siemer