1. Referencing styles and JS files
<link href= "~/content/scripts/plugins/simditor/css/simditor.css" rel= "stylesheet"/><script src= "~/ Content/scripts/plugins/simditor/js/simditor.js "></script>
2. Initialize Simditor
var editor = null; $ (function () { //can refer to http://www.jcodecraeer.com/a/javascript/2015/0201/2393.html editor = new Simditor ({ textarea: $ (' #NewsContent '), placeholder: ' Enter the announcement here ... ', toolbar: [' title ', ' Bold ', ' Italic ', ' Underline ', ' strikethrough ', ' color ', ' | ', ' ol ', ' ul ', ' blockquote ', ' Code ', ' table ', ' | ', ' link ', ' image ', ' hr ', ' | ', ' in Dent ', ' outdent '], upload: { url: '/publicinfomanage/notice/savepic ',//File Upload interface address params:null,//key-value pair, Specify the additional parameters of the file upload interface, when uploading with the file filekey: ' Filedatafilename ',//server side get File data parameter name Connectioncount:3, Leaveconfirm: ' Uploading file '} })
Upload settings will appear in the options
Before implementing the function, you need to modify the referenced JS file, use the view browser's audit element function to view, found the input button does not have the Name property
3. Open the Simditor.js file to search the Accept property, then add "name=" FileData "properties, a total of two need to add, as
4. Write the background processing picture code
123456789101112131415161718192021222324 |
/// <summary>
/// 上传图片
/// </summary>
/// <returns></returns>
public ActionResult SavePic()
{
HttpPostedFileBase file = Request.Files[
"fileDataFileName"
];
if
(file !=
null
)
{
string
strPath = HttpContext.Server.MapPath(
"/Content/Upload/"
);
if
(!Directory.Exists(strPath))
{
Directory.CreateDirectory(strPath);
}
string
filePath = Path.Combine(strPath, Path.GetFileName(file.FileName));
file.SaveAs(filePath);
return
Success(
"上传成功!"
);
}
else
{
return
Success(
"上传失败!"
);
}
}
|
Simditor uploading local images in MVC