0

I'm working on on a phonegap application. I'm using an asp.net project to do my development in and then I am compiling all my files to static html files for the phonegap app.

I want to take advantage of razor syntax for things like including files and simple logic.

Is there a way to run razor code in an html file?

I am currently using cshtml files, but PhoneGap will only accept html files. I currently have RazorEngine to compile the cshtml files to html files, but then I also need to update every link from .cshtml to .html and things are getting complicated.

Code example for razor templating...

@using System.IO;
@using RazorEngine;

@{  // render panelhtml and header html once, and then print it out below in each page
    string panelHtml = Razor.Parse(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "/Views/Shared/_Panel.cshtml"));  
    string headerHtml = Razor.Parse(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "/Views/Shared/_HeaderLoggedIn.cshtml"));  
    string topHtml = Razor.Parse(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "/Views/Shared/_HeaderLoggedIn.cshtml"));

    WriteLiteral(topHtml);          
}

<!-- pageDebug -->
    <div data-role="page" id="pageDebug"  data-add-back-btn="true">

        @{  WriteLiteral(panelHtml);  }

        @{  WriteLiteral(headerHtml);  }
TWilly
  • 4,863
  • 3
  • 43
  • 73
  • code example of a problem you're facing? you can probably get around it w/o razor syntax – hunter Apr 05 '13 at 16:27
  • Note: This did not work for me. http://stackoverflow.com/questions/5110970/can-i-serve-html-files-using-razor-as-if-they-were-cshtml-files-without-changi When loading a static html file from a url the App_Start code was not generated. I am running in an MVC project and don't want to route through the controllers. – TWilly Apr 05 '13 at 16:50
  • I think a better phonegap/cordova architecture using .NET would be to have an ASP.NET API project serving data to the app, not what you're doing. – hunter Apr 05 '13 at 19:20

0 Answers0