使用razor引擎解析cshtml文件

Using razor engine to parse cshtml file

我有两个应用程序。其中一个是网络应用程序,另一个是移动应用程序。我正在尝试解析 Web 应用程序的其中一个视图并为移动应用程序编译一个 html 文件。我的view在web app中的结构如下

  1. App.cshtml
    • partialview1.cshtml
    • partialview2.cshtml
    • .....

Web 应用程序是在 asp.net mvc 中构建的,我正在使用 Microsoft visual studio cordova 构建移动应用程序。

我有一个单独的项目,它采用 App.cshtml 并为移动应用程序编译 index.html。这是我的 App.cshtml 文件

的结构
@model Account
@{
Layout = "~/Views/Shared/_Layout.cshtml";
ViewBag.Title = Texts.App;
}

@section head{
@Styles.Render("~/Content/css/app")
}

@section scripts {

@Scripts.Render("~/bundles/moment")
@Scripts.Render("~/bundles/tippnett/app")

<script>
    var userId = '@Model.Id';
    TippNett.StartApp();

</script>

}
<div id="appview" class="loading">
<div id="workspace" class="map_canvas">
    <section class="other-stuff">
        @RenderPage("~/Views/Home/subPagesForApp/_locationWindow.cshtml")
        @RenderPage("~/Views/Home/subPagesForApp/_moveLocationWindow.cshtml")
        @RenderPage("~/Views/Home/subPagesForApp/_orderWindow.cshtml")
        @RenderPage("~/Views/Home/subPagesForApp/_createLocation.cshtml")
        @RenderPage("~/Views/Home/subPagesForApp/_ordersListWindow.cshtml")
        @RenderPage("~/Views/Home/subPagesForApp/_reportAbuse.cshtml")
    </section>
</div>

<div class="locations-list" data-bind="visible:locationView">
    @RenderPage("~/Views/Home/subPagesForApp/_locationList.cshtml")
</div>

<div id="loading-wale">
    <div id="loading-info">
        <div>
            <i class="spinner">&nbsp;</i>
        </div>
        <div>@Texts.Loading</div>
    </div>
</div>

</div>
<div class="show-for-small" id="stick-menu" data-role="footer">
<div class="icon-bar three-up ">
    <a class="item active locations" data-bind="click: openLocationView.bind($data,true)">
        <i class="fi-marker"></i>
        <label>@Texts.Location</label>
    </a>
    <a class="item maps" data-bind="click: openMapView.bind($data,true)">
        <i class="fi-map"></i>
        <label>@Texts.Maps</label>
    </a>
    <a class="item notifications" data-bind="click: openOrders.bind($data,true)">
        <i class="fi-list"></i>
        <span class="order-notification-counter notification-counter" data-bind=" text: orders().length,visible: orders().length > 0"></span>
        <span class="matches-notification-counter notification-counter" data-bind=" text: matches().length,visible: matches().length > 0"></span>
        <label>
            @Texts.OrdersLabel
        </label>
    </a>
</div>

我调查了 RazorEngine.Razor.Compile,但没有成功。我也查看了这个库 http://razorengine.codeplex.com/,但找不到任何地方。

cshtml 是 运行 服务器端,cordova 应用 运行 在移动端(客户端)
所以我认为你不能 运行 移动设备上的 mvc,你应该使用一些移动框架
html作为模板,js调用ajax获取数据,并绑定到html模板。