Posted on 28th March 2013One Response
Using Mustache (Nustache) with traditional ASP.NET (non MVC)
  1. Download Nustache
  2. Extract zip file and open solution file.
  3. If you don’t have MVC3 installed you will get a warning that Visual Studio cannot open the project
  4. Click OK and continue
  5. Nustache.Mvc3 project will be grayed out. Right click the solution in Solution Explorer window and add new ASP .NET Application. I named it NustacheWebApplication. This will create Default.aspx page.
  6. Add new “Template” folder to the solution.
  7. Copy Index.mustache file from \ Nustache-master\Nustache.Mvc3.Example\Views\Home to the new Template folder.
  8. Add reference to the Nustache.Core project.
  9. Open Default.aspx page and add Literal control;

    <asp:LiteralID=”LiteralText runat=”server”></asp:Literal>

  10. Open Default.aspx.cs file and add using statements:

    using Nustache.Core;

  11. Then the following code to the Page_Load method:

    protected void Page_Load(object sender, EventArgs e)

    {

    var dataObject = new

    {

    DoModelPropertiesWork = “Model properties work!,

    DoesHtmlEncodingWork = “<em>Should this be encoded?</em>”,

    DoesInternationalCharacterEncodingWork = Iñtërnâtiônàlizætiøn,

    DoesRussianCharacterEncodingWork = Привет,как дела

    };

    var html = Nustache.Core.Render.FileToString(

    Server.MapPath(@”~\Temlates\Index.mustache),

    dataObject

    );

    LiteralText.Text = html;

    }

  12. You may need to unload Nustache.Mvc3 project from the solution if you don’t have MVC 3 installed before you run the application.
Comments

Warning: A non-numeric value encountered in H:\root\home\idenys-001\www\gold-estate\wp-content\themes\technical-speech\comments.php on line 20

Warning: A non-numeric value encountered in H:\root\home\idenys-001\www\gold-estate\wp-content\themes\technical-speech\comments.php on line 21
Leave a Response
XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

  This Wordpress Theme is protected. Thanks to 1 Hour Loan