Tagged: spark Toggle Comment Threads | Keyboard Shortcuts

  • danielsaidi 10:56 am on January 14, 2011 Permalink | Reply
    Tags: , project template, spark   

    Flush the Visual Studio Template Cache 

    After my last blog post about adding Spark to an ASP.NET MVC 2 project, I decided to create a project template that uses Spark instead of the default Web Forms view engine.

    However, even though I added my new template to the Visual Studio project template folder, it still did not turn up in the project list when I wanted to create a new project.

    What you have to do is to flush the Visual Studio Template Cache, which will make Visual Studio update the list of project templates that are available. It is really easy to do.

    In the command prompt, just execute the following:

       devenv /installvstemplates

    If your command prompt does not find devenv, just navigate to the .exe file, for instance:

       C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE>

    After doing so, just choose to create a new project in Visual Studio and the template should appear in the list.

  • danielsaidi 12:58 pm on January 13, 2011 Permalink | Reply
    Tags: , , razor, spark, , validationsummary   

    Adding Spark to ASP.NET MVC 2.0 

    After almost a year’s curiosity, with other stuff stealing my time, I have finally some time to have a look at the Spark View Engine. Since the Razor View Engine will be shipped together with ASP.NET MVC 3.0, I decided to give Spark a shot before Razor.

    I will not go into detail about what Spark is, what it does etc. etc. The official web site has some good info and this blog helped me get started. I will just describe how to get Spark up and running and get it to play alongside a default ASP.NET MVC application.

    Get Spark up and running

    The first thing we have to do is to add Spark to our application. Visit the Spark web site, download and unzip the latest release, add it to your solution and add references to Spark.dll and Spark.Web.Mvc.dll.

    Of course, if you use NuGet, just right-click the references folder and choose Add package reference…

    …then search for spark and install sparkmvc.

    This will automatically add most of what you need. Really convenient!

    However, for Spark to work, we need to register it when the application starts. Do this by adding the following to Application_Start in global.asax.cs:

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

    Finally, I recommend adding the following to web.config, although it is optional:

          <section name="spark" type="Spark.Configuration.SparkSectionHandler, Spark"/>
          <compilation debug="true" />
          <pages automaticEncoding="true" />

    That’s it – Spark is now added to your app and runs alongside the default Web Forms view engine. Any views not using Spark will still work.

    Converting views to Spark

    In short, all you have to do to convert your views (master pages, user controls and pages) to spark is to:

    • Rename Site.master to Application.spark
    • Rename all user controls to _NAME.spark (the underline makes it possible to add user controls as HTML elements)
    • Rename all pages to NAME.spark
    • In all master page, user control and page files, remove the topmost tag
    • In Application.spark, replace all ContentPlaceHolders tags with use spark tags
    • In all pages, replace all Content tags with contentspark tags

    You also have to replace:

       <%   =>   ${

    For strongly types views,you can type ViewData and the Model like this:

       <viewdata Message="string" model="SparkTemplate.Models.LogOnModel" />

    Note that the name of the ViewData key is defined as is while the model tag is defined in lower-case. You can then access the model like this:


    Other than that, everything just seem to work.

    Worth noticing is that you should use ! instead of $ for ValidationSummary and ValidationMessageFor Рotherwise, empty strings will render the full Spark expression.

Compose new post
Next post/Next comment
Previous post/Previous comment
Show/Hide comments
Go to top
Go to login
Show/Hide help
shift + esc