首先、下載Uediotr,初次使用建議下載全版和實(shí)例,可以一一學(xué)習(xí)研究。下載地址:http://ueditor.baidu.com/download.html
其次、在MVC中建立一個(gè)文件件,如圖
,然后把下載的文件夾中的幾個(gè)文件全部包含進(jìn)來(lái).再次、我們?cè)贏sp.net mvc中可以建立一個(gè)測(cè)試Controller.在其View中輸入引用editor_config.js 和editor_ui_all_min.js 同時(shí)引用themes下面的ueditor.css。然后在需要出現(xiàn)
編 輯框的地方輸入
- <textarea id="editor"></textarea>
- <script type="text/javascript">
- var editor = new baidu.editor.ui.Editor({
- UEDITOR_HOME_URL: '/Uedit/',
- iframeCssUrl: '/Uedit/themes/default/iframe.css',
- initialContent: '',
- minFrameHeight: 550
- });
- editor.render('editor');
- </script>
注意:UEDITOR_HOME_URL: '/Uedit/',
iframeCssUrl: '/Uedit/themes/default/iframe.css', 這兩行js為Ueditor放置的目錄和iframe.css所在的位置。然后運(yùn)行??梢园l(fā)現(xiàn)Ueditor的基本樣子已經(jīng)出現(xiàn),但是圖片上傳部分存在問(wèn)題。
最后、修改圖片上傳部分的問(wèn)題。找到\UEdit\dialogs\image。里面有兩個(gè)php文件,可以把這兩個(gè)php文件更名為html文件,我們主要使用upload.php.我們把他修改為upload.html,同時(shí)修改其中的代碼如下:
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
- "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <title></title>
- <style type="text/css">
- *{margin:0;padding:0}
- html,body{margin-top:-2px;}
- #filename{
- position:absolute;
- z-index:9999;
- left:150px;
- opacity:0;
- filter:alpha(opacity=0);
- width:50px;
- height:21px;
- }
- #url{
- position:absolute;left:0;
- width:146px;height:21px;background: #FFF;border:1px solid #d7d7d7;padding: 0; margin-top:-1px;
- }
- #flag{
- position:absolute;left:150px;
- }
- .btn2 {
- border:0;
- background: url("../../themes/default/images/button-bg.gif") no-repeat;
- font-size:12px;
- height:23px;
- width:50px;
- text-align: center;
- cursor: pointer;
- }
- .btn1 {
- border:0;
- background: url("../../themes/default/images/button-bg.gif") 0 -27px no-repeat;
- font-size:12px;
- height:23px;
- width:50px;
- text-align: center;
- cursor: pointer;
- }
- </style>
- <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
- </head>
- <body>
- <form id="upImg" action="/upload/UploadImage/" method="post" enctype="multipart/form-data" style="margin-top:5px;">
- <input type="hidden" id="path" name="path" />
- <input id="filename" name="filename" type="file" onmouseover="document.getElementById('flag').className='btn1'" onmouseout="document.getElementById('flag').className='btn2'" />
- <input id="url" type="text" name="url" readonly="readonly" value="" />
- <input class="btn2" id="flag" name="flag" type="button" value="瀏覽…" onmouseover="this.className='btn1'" onmouseout="this.className='btn2'" onclick="sub()" />
- </form>
- <script type="text/javascript">
- var url = document.getElementById('url');
- url.onkeydown = function(evt){
- evt = event || evt;
- evt.preventDefault ?evt.preventDefault() : (evt.returnValue = false);
- }
- var form = document.getElementById("upImg");
- document.getElementById("filename").onchange = function(){
- //------------------------------------------
- //如果需要上傳功能,請(qǐng)取消以下兩行注釋即可?。。。?/div>
- //alert("由于安全原因,本demo暫不提供圖片上傳服務(wù)!下載包中包含了支持php版上傳功能的相關(guān)文件,修改后即可使用。");
- //return;
- //------------------------------------------
- document.getElementById('path').value = this.value;
- form.submit();
- }
- function sub(){
- var file = document.getElementById("filename");
- //file.click();
- if(file.click) file.click();
- else if(file.fireEvent) file.fireEvent('onclick');
- else if(document.createEvent){
- var evt = document.createEvent("MouseEvents");
- evt.initEvent("click", true, true);
- file.dispatchEvent(evt);
- }
- }
- </script>
- </body>
- </html>
我們要把圖片上傳到“/upload/UploadImage/”,所以我們需要先建立一個(gè)upload的controller,然后建立一個(gè)UploadImage的action.具體的C#代碼如下:
- public class UploadController : Controller
- {
- //
- // GET: /Upload/
- [HttpGet]
- public ActionResult Upload()
- {
- string url = Request.QueryString["url"];
- if (url == null)
- {
- url = "";
- }
- ViewData["url"] = url;
- return View();
- }
- [HttpPost]
- public ActionResult UploadImage(HttpPostedFileBase filename)
- {
- //具體的保存代碼
- return View();
- }
- }
在view中代碼如下:
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
- "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <title></title>
- <style type="text/css">
- *{margin:0;padding:0}
- html,body{margin-top:-2px;}
- #filename{
- position:absolute;
- z-index:9999;
- left:150px;
- opacity:0;
- filter:alpha(opacity=0);
- width:50px;
- height:21px;
- }
- #url{
- position:absolute;left:0;
- width:146px;height:21px;background: #FFF;border:1px solid #d7d7d7;padding: 0; margin-top:-1px;
- }
- #flag{
- position:absolute;left:150px;
- }
- .btn2 {
- border:0;
- background: url("/UEdit/themes/default/images/button-bg.gif") no-repeat;
- font-size:12px;
- height:23px;
- width:50px;
- text-align: center;
- cursor: pointer;
- }
- .btn1 {
- border:0;
- background: url("/UEdit/themes/default/images/button-bg.gif") 0 -27px no-repeat;
- font-size:12px;
- height:23px;
- width:50px;
- text-align: center;
- cursor: pointer;
- }
- </style>
- <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
- </head>
- <body>
- <form id="upImg" action="/upload/UploadImage/" method="post" enctype="multipart/form-data" style="margin-top:5px;">
- <input type="hidden" id="path" name="path" />
- <input id="filename" name="filename" type="file" onmouseover="document.getElementById('flag').className='btn1'" onmouseout="document.getElementById('flag').className='btn2'" />
- <input id="url" type="text" name="url" readonly="readonly" value="<%=ViewData["url"] %>" />
- <input class="btn2" id="flag" name="flag" type="button" value="瀏覽…" onmouseover="this.className='btn1'" onmouseout="this.className='btn2'" onclick="sub()" />
- </form>
- <script type="text/javascript">
- var url = document.getElementById('url');
- url.onkeydown = function (evt) {
- evt = event || evt;
- evt.preventDefault ? evt.preventDefault() : (evt.returnValue = false);
- }
- var form = document.getElementById("upImg");
- document.getElementById("filename").onchange = function () {
- //------------------------------------------
- //如果需要上傳功能,請(qǐng)取消以下兩行注釋即可!?。?!
- //alert("由于安全原因,本demo暫不提供圖片上傳服務(wù)!下載包中包含了支持php版上傳功能的相關(guān)文件,修改后即可使用。");
- //return;
- //------------------------------------------
- document.getElementById('path').value = this.value;
- form.submit();
- }
- function sub() {
- var file = document.getElementById("filename");
- //file.click();
- if (file.click) file.click();
- else if (file.fireEvent) file.fireEvent('onclick');
- else if (document.createEvent) {
- var evt = document.createEvent("MouseEvents");
- evt.initEvent("click", true, true);
- file.dispatchEvent(evt);
- }
- }
- </script>
- </body>
- </html>
- <html><head>
- <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
- <style type="text/css">
- *{margin:0;padding:0}
- html,body{margin-top:-2px;}
- #filename{
- position:absolute;
- z-index:9999;
- left:150px;
- opacity:0;
- filter:alpha(opacity=0);
- width:50px;
- height:21px;
- }
- #url{
- position:absolute;left:0;
- width:146px;height:21px;background: #FFF;border:1px solid #d7d7d7;padding: 0; margin-top:-1px;
- }
- #flag{
- position:absolute;left:150px;
- }
- .btn2 {
- border:0;
- background: url("/UEdit/themes/default/images/button-bg.gif") no-repeat;
- font-size:12px;
- height:23px;
- width:50px;
- text-align: center;
- cursor: pointer;
- }
- .btn1 {
- border:0;
- background: url("/UEdit/themes/default/images/button-bg.gif") 0 -27px no-repeat;
- font-size:12px;
- height:23px;
- width:50px;
- text-align: center;
- cursor: pointer;
- }
- </style>
- </head>
- <body>
- <form id="upImg" action="/upload/UploadImage/" method="post" enctype="multipart/form-data" style="margin-top:5px;">
- <input id="filename" name="filename" type="file" onmouseover="document.getElementById('flag').className='btn1'" onmouseout="document.getElementById('flag').className='btn2'" />
- </form>
- <script type="text/javascript">
- parent.reloadImg('<%=ViewData["url"] %>');
- location.href="/upload/upload/?url=<%=ViewData["url"] %>";
- </script>
- </body></html>
運(yùn)行后發(fā)現(xiàn)Ueditor在Asp.net 中可以正常使用。
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
聯(lián)系客服