原創|使用教程|編輯:王香|2018-07-03 11:56:50.000|閱讀 255 次
概述:本教程介紹如何使用Razor將TextControl.Web集成到MVC應用程序中。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
確保在開發計算機上至少安裝了適用于ASP.NET的TX Text Control .NET Server的試用版:
下載試用版打開Visual Studio并創建一個新的ASP.NET Web應用程序。確保選擇.NET Framework 4.5作為.NET Framework項目version.xx
在下一個對話框New ASP.NET Project中,選擇Empty作為項目模板。選中MVC和Web API復選框以添加文件夾和核心參考。單擊確定關閉對話框。
單擊“ 項目”主菜單中的“ 管理NuGet包... ” 。從在線包源面板中選擇nuget.org。在右上角,搜索TXTextControl.Web。找到最新版本,然后單擊“ 安裝”。
確保更新Microsoft ASP.NET MVC包(如果它們在“ 更新”面板中可用)。關閉對話框關閉。
在Solution Explorer中,選擇App_Data并從Project主菜單中選擇New Folder,并將文件夾命名為Documents。選擇新創建的文件夾Documents,然后從Project主菜單中單擊Add Existing Item ....
瀏覽到以下TX Text Control安裝文件夾:C:\ Program Files \ Text Control GmbH \ TX文本控件25.0.NET Server for ASP.NET \ Samples \ Demo \
選擇兩個文件invoice.docx和sample_db.xml,然后使用Add確認。
在Solution Explorer中,選擇Controllers文件夾,然后從Project主菜單中選擇Add New Item .... 在打開的對話框Add New Item中,選擇MVC 5 Controller - Empty并使用Add確認。將名稱設置為HomeController并通過單擊“ 添加”按鈕將其插入。
在Solution Explorer中,選擇新創建的文件夾Home,然后從Project主菜單中選擇Add New Item .... 選擇MVC 5 View Page(Razor),將其命名為Index并使用Add確認。
從Views - > Home文件夾中打開Index.cshtml視圖。將以下Razor代碼添加到視圖的頂部:
@using TXTextControl.Web @using TXTextControl.Web.MVC
將以下HtmlHelper代碼添加到視圖頁面的末尾:
@Html.TXTextControl().TextControl(settings => { settings.DocumentFileDirectory = Server.MapPath("~/App_Data/Documents"); }).LoadXMLDatabase( Server.MapPath("~/App_Data/Documents/sample_db.xml")).LoadText( Server.MapPath("~/App_Data/Documents/invoice.docx"), StreamType.WordprocessingML).Render()
完整的Index.cshtml現在應該如下所示:
@using TXTextControl.Web @using TXTextControl.Web.MVC @{ ViewBag.Title = "Index"; } <h2>Index</h2> @Html.TXTextControl().TextControl(settings => { settings.DocumentFileDirectory = Server.MapPath("~/App_Data/Documents"); }).LoadXMLDatabase( Server.MapPath("~/App_Data/Documents/sample_db.xml")).LoadText( Server.MapPath("~/App_Data/Documents/invoice.docx"), StreamType.WordprocessingML).Render()
編譯并啟動應用程序。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn