ASP.NET MVC4 使用UEditor富文本

來源:互聯網
上載者:User

標籤:xmlns   min   dir   hot   rect   dex   frame   erro   sse   

原帖:http://user.qzone.qq.com/369175376/infocenter?ptlang=2052  第一步:先到http://ueditor.baidu.com/website/download.html去下載
 第二步:把下載的檔案改成ueditor名稱,添加到Content檔案夾裡面
 
第三步:在ueditor檔案夾下面的net檔案夾建立一個upload檔案夾裝上傳的圖片

第四步:找到net檔案夾裡面的config.json檔案,在找到所有的
 /* 圖片訪問路徑首碼 */
 然後在前面的途徑加上:/Content/
 
 其它配置圖片訪問路徑首碼,以此類推,因為我們把ueditor檔案夾放在了Content檔案夾下面
第五步:建立一個Home控制器,點Index右鍵產生視圖
在視圖裡面添加:
<script src="~/Content/ueditor/ueditor.config.js"></script><script src="~/Content/ueditor/ueditor.all.js"></script><link href="~/Content/ueditor/themes/iframe.css" rel="stylesheet" /><script src="~/Content/ueditor/lang/zh-cn/zh-cn.js"></script>
注意先後順序,不要顛倒了!  <script type="text/javascript">        var editor = new baidu.editor.ui.Editor({            UEDITOR_HOME_URL: ‘/Content/ueditor/‘,//配置編輯器路徑            iframeCssUrl: ‘/Content/ueditor/themes/iframe.css‘,//樣式路徑            initialContent: ‘歡迎使用ueditor‘,//初始化編輯器內容            autoHeightEnabled: true,//高度自動成長            minFrameHeight: 500//最小高度        });        editor.render(‘editor‘);    </script>@using(Html.BeginForm("Index","Home",FormMethod.Post)){    <textarea id="editor" name="editor"> </textarea>    <input type="submit" value="提交" />}
這個是Index頁面裡面的內容
第六步:在控制器裡面在添加一個httppost的Index方法
[HttpPost]         [ValidateInput(false)]        public ActionResult Index(FormCollection fc)        {            var content = fc["editor"];            return View();        } 
注意:  [ValidateInput(false)]這是解決一直報安全問題的辦法 
 第七步:產生會報錯,在ueditor裡面net檔案的bin裡面的Newtonsoft.Json無法拷貝到當前項目裡面的bin目錄裡面,那是因為ueditor的net檔案裡面的Newtonsoft.Json的版本要高於項目裡面的版本,把項目裡面的Newtonsoft.Json引用刪除掉,在引用ueditor裡面net檔案的bin裡面的Newtonsoft.Json的dll檔案
第八步:在Web.config裡面找到 <runtime>節點
在它下面的<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
節點裡面添加
 <dependentAssembly>        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />      </dependentAssembly>
如上節點,就可以解決  Newtonsoft.Json無法引用的問題
以上步驟都作完成,就可以實現富文本並且可以上傳圖片了! 

ASP.NET MVC4 使用UEditor富文本

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.