فعال سازی قسمت ارسال فایل و تصویر ویرایشگر آنلاین RedActor در ASP.NET MVC
نویسنده: وحید نصیری
تاریخ: ۱۳۹۱/۰۵/۰۳ ۲۳:۲۰
آدرس: www.dntips.ir
| مطالب | ۳۶۹۴ |
| نویسندگان | ۲۷۶ |
| گروههای مطالب | ۱۰۲۴ |
| نقشههای راه | ۱۱۹ |
| دورهها | ۱۴ |
| اشتراکها | ۱۷۹۱۴ |
@Html.TextAreaFor(model => model.ArticleBody, htmlAttributes: new { style = "width:98%; height:500px" })
<script type="text/javascript">
$('#ArticleBody').redactor({
autoformat: false,
convertDivs: false
});
</script>
<script type="text/javascript">
$('#ArticleBody').redactor({
imageUpload: "@Url.Action(result: MVC.RedactorUpload.ImageUpload())",
fileUpload: "@Url.Action(result: MVC.RedactorUpload.FileUpload())",
linkFileUpload: "@Url.Action(result: MVC.RedactorUpload.FileLinkUpload())"
, autoformat: false
, convertDivs: false
});
</script>
[HttpPost]
public virtual ActionResult ImageUpload(HttpPostedFileBase file)
{
}
[AllowUploadSpecialFilesOnly(".jpg,.gif,.png")]
return Content("<img src='" + path + "' />");
return Content("<a href=" + path + ">" + someName + "</a>");
return Content(path);
سلام
آقای نصیری میشه طریقه استفاده از این ادیتور رو برای asp.net webform هم شرح بدهید؟
باتشکر
public class Upload : IHttpHandler {
public void ProcessRequest (HttpContext context) {
HttpPostedFile uploads = context.Request.Files["upload"];
//... save the file
// return context.Response.Write(...)
// and then context.Response.End();
string fileName = Path.GetFileName(file.FileName);
string filePath = "~/App_Data/Uploads/Pic/" + file.FileName;
if (file.ContentLength > 0 && fileName != null)
{
string path = Path.Combine(Server.MapPath("~/App_Data/Uploads/Pic"), fileName);
file.SaveAs(path);
}
return Content("<img src='" + filePath + "' />");
return Content("<img src='" + path + "' />");
جناب نصیری من بعد از اجرای خط
return Content("<img src='" + filename + "' />");
//filename =C:\Users\mta\Documents\Visual Studio 2010\Projects\IAUG\GIAU\Images\Actors.png
e.match(/\{.*\}/)[0]
virtualpath = "Images/Main.jpg";
return Content("<img src='" + virtualpath + "' />");
var c=e.match(/\{.*\}/)[0];
//e=<IMG src="Images/Main.jpg">
//e.match=null !
// displaying file $array = array( 'filelink' => '/images/'.$filename ); echo stripslashes(json_encode($array));
var array = new { filelink = "Images/k1.jpg" };
return Json(array, System.Net.Mime.MediaTypeNames.Text.Plain, JsonRequestBehavior.AllowGet);
$array = array( 'filelink' => '/files/'.$_FILES['file']['name'], 'filename' => $_FILES['file']['name'] ); echo stripslashes(json_encode($array));
var array = new { filelink = "files/myfile.zip", filename="myfile.zip" };
return Json(array, System.Net.Mime.MediaTypeNames.Text.Plain, JsonRequestBehavior.AllowGet);
body{
font-family:Tahoma,sans-serif;
font-size:9pt;
margin:0;padding:0;
overflow-x:hidden;
background:#fff;
direction:rtl
}
var array = new { filelink = "files/myfile.zip", filename="myfile.zip" };
return Json(array, System.Net.Mime.MediaTypeNames.Text.Plain, JsonRequestBehavior.AllowGet);context.Response.Write("{'filelink'='" + filePath + "'}");{ "filelink": "/images/img.jpg" }{ "filelink": "/files/file.doc", "filename": "Filename" }[Required(ErrorMessageResourceType = typeof(ValidationErrorsResource),
ErrorMessageResourceName = ResourceKeys.ValidationErrorsResource.RequiredField)]
[MaxLength]
[DisplayName("متن")]
[AllowHtml]
public string FullDescription { get; set; }<div>متن: </div>
<div>@Html.TextAreaFor(p => p.FullDescription)</div>
<div>@Html.ValidationMessageFor(p => p.FullDescription)</div>
$('#FullDescription').redactor({
autoformat: false,
convertDivs: false
});[HttpPost]
[AllowUploadImagesOnly(".jpg,.gif,.png")]
public virtual ActionResult ImageUpload(HttpPostedFileBase file)
{
var newFileName = Server.MapPath(Path.Combine(Links.SiteContents.Upload.Url(), file.FileName));
file.SaveAs(newFileName);
var array = new { filelink = newFileName };
return Json(array, MediaTypeNames.Text.Plain, JsonRequestBehavior.AllowGet);
}<label>
Code:</label>
<textarea id="redactor_insert_code_area" name="redactor_insert_code_area" style="height: 211px; width: 538px;" />
<label>
Language:</label>
<select id="redactor_insert_code_lang">
<option>CSharp</option>
<option>VB</option>
<option>JScript</option>
<option>Sql</option>
<option>XML</option>
<option>CSS</option>
<option>Java</option>
<option>Delphi</option>
</select>
<br />
<input type="button" name="insert" id="redactor_insert_btn" value="%RLANG.insert%" /> showCodesPage: function () {
this.modalInit('Insert Code', this.opts.path + '/plugins/paste_code.html', 600, $.proxy(function () {
var sel = this.getSelection();
var currentCode = '';
this.opts.codeElement = false;
if ($.browser.msie) {
var parent = this.getParentNode();
if (parent.nodeName === 'PRE') {
this.opts.codeElement = parent;
currentCode = $(parent).text();
} else {
if (this.oldIE()) {
currentCode = sel.text;
} else {
currentCode = sel.toString();
}
}
} else {
if (sel && sel.anchorNode && sel.anchorNode.parentNode.tagName === 'PRE') {
this.opts.codeElement = sel.anchorNode.parentNode;
currentCode = $(sel.anchorNode.parentNode).text();
} else {
currentCode = sel.toString();
}
}
if (this.opts.codeElement) {
$("#redactor_insert_btn").val("Update");
}
if (currentCode) $('#redactor_insert_code_area').val(currentCode);
$('#redactor_insert_code_area').focus();
$('#redactor_insert_btn').click($.proxy(this.insertCodesPage, this));
}, this));
},
insertCodesPage: function () {
var lang = $("#redactor_insert_code_lang").val();
var code = $("#redactor_insert_code_area").val();
code = code.replace(/\s+$/, ""); //rtrim;
code = $('<span/>').text(code).html(); // encode
this.$editor.focus();
var preBlock;
if (this.opts.codeElement) {
preBlock = $(this.getParentNode());
} else {
preBlock = $("<pre/>");
}
preBlock.replaceWith("");
var htmlCode = "<pre language='" + lang + "' name='code'>" + code + "</pre></div>";
var codeBlock = "<div align='left' dir='ltr'>" + htmlCode + "</div><br/>";
this.execCommand('inserthtml', codeBlock);
this.modalClose();
}, code:
{
title: 'Code',
func: 'showCodesPage'
}, body .redactor_toolbar li a.redactor_btn_code span { background: url(../img/code_red.png) no-repeat center; } this.modalInit('Insert Code', this.opts.path + '/plugins/paste_code.html', 600, $.proxy(function () { this.opts.path
{
title: 'Code',
func: 'showCodesPage'
}, public ActionResult FileUpload(HttpPostedFileBase file)
{
if (file.ContentLength > 0)
{
string filePath = Path.Combine(HttpContext.Server.MapPath("../uploade/"), Path.GetFileName(file.FileName));
file.SaveAs(filePath);
}
return Content("<img src='/uploade/" + file.FileName + "' />");
} [HttpPost]
public ActionResult ImageUpload(HttpPostedFileBase file)
{
string path = "";
var FileName = "";
if (file.ContentLength > 0)
{
FileName = Path.GetFileName(file.FileName);
string Extension = file.ContentType;
string[] ExtensionList = { "image/jpg", "image/jpeg", "image/gif", "image/pmg" };
if (ExtensionList.Contains(Extension.ToLower()))
{
path = Path.Combine(Server.MapPath("~/Images/uploads"), FileName);
file.SaveAs(path);
}
}
var array = new { filelink = @"Images\uploads\" + FileName };
return Json(array, System.Net.Mime.MediaTypeNames.Text.Plain, JsonRequestBehavior.AllowGet);
} if (this.uploadOptions.success)
{
if (typeof d !== 'undefined')
{
// Remove bizarre <pre> tag wrappers around our json data:
var rawString = d.body.innerHTML;
var jsonString = rawString.match(/\{.*\}/)[0];
this.uploadOptions.success(jsonString);
} var jsonString = rawString.match(/\{.*\}/)[0]; 0x800a138f - JavaScript runtime error: Unable to get property '0' of undefined or null reference