我的观点是:
<script type="text/javascript">
$('#Body').redactor({
fileUpload: "@Url.Action(controllerName: "RedactorUpload", actionName: "FileUpload")"
, autoformat: false
, convertDivs: false
, direction: 'rtl'
, autoresize: false
});
我在控制器中的动作是:
[HttpPost]
[AllowUploadSafeFiles]
public virtual ActionResult FileUpload(HttpPostedFileBase file,string section)
{
ActionResult result;
string fileName = Path.GetFileName(file.FileName);
string relativePath = "/Content/"+section+"/Files/";
string absolutePath = Server.MapPath("~" + relativePath + fileName);
if (file.ContentLength > 0 && fileName != null)
{
file.SaveAs(absolutePath);
var array = new { filelink = relativePath + fileName, filename = fileName };
result = Json(array, System.Net.Mime.MediaTypeNames.Text.Plain, JsonRequestBehavior.AllowGet);
}
else
{
result = Content("invalid file!");
}
return result;
}
我想从我的观点发送部分到行动。 section是字符串变量。 action中的relativePath变量是动态的,由视图确定(通过参数从视图传递)。