百度上下载了xheditor1.2.1

一、使用方法:

1、把解压的目录copy到VS中;

2、在需要用的View页面中引用js

<script src="~/xheditor/xheditor-1.2.1.min.js"></script>
<script src="~/xheditor/xheditor_lang/zh-cn.js"></script>

 

这里注意,如果你的目录不是xheditor,那么对不起,你一辈子也看不到效果,这儿耗费我了2个小时!

3、在页面中加一个TextArea控件

 

<textarea id="elm2" name="elm2" class="xheditor-mfull {upImgUrl:'@Url.Action("Upload")',upImgExt:'jpg,jpeg,gif,png'}" style="width: 480px;height:500px"></textarea>

 

这里使用的是class方式,也可以用JS方式,具体去看xheditor使用文档

 

现在这可以用了,但还没有接收文件,就是那个@Url.Action("Upload")

 

进入相关controller,加一个公共的Upload

 1         #region 上传文件接收
 2         [HttpPost]
 3         public string Upload()
 4         {
 5             int MaxSize = 2097152;     // 最大上传大小,默认是2M
 6             string newFile="";
 7             string ext="";
 8             string fn = "";
 9             try
10             {
11                 HttpFileCollectionBase fc = Request.Files;
12                 HttpPostedFileBase f = Request.Files[0];
13                 if (f.ContentLength > MaxSize || f.ContentLength == 0)
14                     return "{'err':'上传失败!文件大小不正确,必须是在0字节以上,2M字节以内','msg':''}";
15 
16                 if (!Directory.Exists(Server.MapPath("~/Upload")))
17                 {
18                     Directory.CreateDirectory(Server.MapPath("~/Upload"));
19                 }
20                 ext = f.FileName.Substring(f.FileName.LastIndexOf("."));
21                 fn = DateTime.Now.ToString("yyyMMddHHmmssfff");
22                 newFile=Server.MapPath("~/Upload") + "\\" + fn + ext;
23                 f.SaveAs(newFile);
24 
25             }
26             catch(Exception ex)
27             {
28                 return "{'err':'上传失败!'"+ex.Message+",'msg':''}";                
29             }
30             return "{'err':'','msg':{'url':'!/Upload/" + fn+ext + "','localname':'" + ext + "','id':'1'}}";
31         }
32         #endregion
上传文件接收

相关文章:

  • 2021-11-02
  • 2022-12-23
  • 2021-10-23
  • 2021-07-26
  • 2021-09-26
  • 2022-12-23
  • 2022-12-23
  • 2021-10-01
猜你喜欢
  • 2021-11-25
  • 2022-12-23
  • 2021-09-19
  • 2022-12-23
  • 2022-12-23
  • 2021-11-06
  • 2022-12-23
相关资源
相似解决方案