2015-07-21 42 views
0

我有兩個應用程序。其中一個是網絡應用程序,另一個是移動應用程序。我正在嘗試從網絡應用程序解析其中一個視圖,併爲移動應用程序編譯一個html文件。我認爲在Web應用程序的結構如下使用剃刀引擎解析cshtml文件

  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/,但無法獲得任何地方。

+0

你能詳細解釋一下「沒有運氣」嗎?當項目轉移到github時,最新版本可以在這裏找到https://github.com/Antaris/RazorEngine。 – matthid

+0

我爲html的東西做了一個自定義模板。我已經能夠迎合html.raw和pagerender的東西,但我正在努力與html.partial功能。你能否提供一個餐飲功能的例子? – mohsinali1317

回答

0

CSHTML運行服務器端,科爾多瓦的應用程序運行在移動(客戶端)
,所以我認爲你不能在移動設備上運行的MVC中,你應該使用一些移動框架
HTML作爲模板,JS調用AJAX獲取數據,並綁定到html模板。

+0

我沒有在移動設備上運行mvc,我只是想解析html並在我的移動應用程序中使用它。 – mohsinali1317

+0

你可以發送一個ajax請求到一些URL,這個URL將返回html.then把它放到你的cordova html頁面的body標籤中。但是還有一些問題。這個鏈接,圖片將會出去你的應用程序 – chenZ