xheditor C# mvc模式下使用

本文介绍如何使用xheditor编辑器,并解决其在不同浏览器间的兼容性问题,具体步骤包括下载最新版本的xheditor,正确引用相关js文件,以及配置html和js代码以确保在IE89、Chrome和IE10上都能正常执行action操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近用到了这个编辑器挺方便的,但是说不上有多好,还遇到了个兼容性问题(IE89可用,chrome和IE10 post不到action)先记录一下吧!

 

首先下载最新版本的xheditor,解压之后,把这几个文件放到项目相关位置

 

 

引用控件js

 

<script src="../../Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="../../Scripts/Plugins/xheditor/xheditor.js" type="text/javascript"></script>
<script src="../../Scripts/Plugins/xheditor/xheditor_lang/zh-cn.js" type="text/javascript"></script>

 

 

html:

 <textarea id="newsContent" name="newsContent" rows="48" cols="160" style="width: 100%"></textarea>

js:

$(document).ready(function () {

 

  $("#newsContent").xheditor({
  tools: 'full',
  upImgUrl: '/HomeNotice/upload',//这里是controller/action (如果不是mvc模式,则为具体的url)
  upImgExt: "jpg,jpeg,gif,png",
  html5Upload:false

  });

 

});

 

 

c#:

[HttpPost]

public ActionResult upload(System.Web.HttpPostedFileBase fileData)
{

string result = "0";
string folder = "/UploadFiles/upImgs";//这里是文件夹路径,
string errMsg = "";

if (fileData != null)
{
try
{
string fileName = fileData.FileName;
if (fileName.LastIndexOf("\\") > 0)
{
fileName = fileName.Substring(fileName.LastIndexOf("\\") + 1);
}
string currentTime = DateTime.Now.ToString("yyyyMMddhhmmss");
Random r = new Random(DateTime.Now.Millisecond);
int rndKey = r.Next(100000, 999999);

result = Path.GetFileName(fileName);//获得文件名,返回进行显示
string saveFileName = string.Format("{0}_{1}", currentTime + rndKey.ToString(), fileName);

string saveFolder = Request.MapPath(string.Format("~{0}", folder));
if (!Directory.Exists(saveFolder))
Directory.CreateDirectory(saveFolder);

fileData.SaveAs(string.Format("{0}\\{1}", saveFolder, saveFileName));

result = string.Format("{0}/{1}", folder, saveFileName);

}
catch (Exception ex) { errMsg = ex.Message; }
}

var data = new { err = errMsg, msg = result };

return this.Content(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(data));//这里不能用Json方法


}

 

转载于:https://www.cnblogs.com/wuyike/p/4443574.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值