Asp.net mvc 4 将字符串变量从视图传递到mvc4中的控制器
我的看法是:Asp.net mvc 4 将字符串变量从视图传递到mvc4中的控制器,asp.net-mvc-4,view,controller,action,Asp.net Mvc 4,View,Controller,Action,我的看法是: <script type="text/javascript"> $('#Body').redactor({ fileUpload: "@Url.Action(controllerName: "RedactorUpload", actionName: "FileUpload")" , autoformat: false , convertDivs: false , direction: '
<script type="text/javascript">
$('#Body').redactor({
fileUpload: "@Url.Action(controllerName: "RedactorUpload", actionName: "FileUpload")"
, autoformat: false
, convertDivs: false
, direction: 'rtl'
, autoresize: false
});
我想将我的视图中的部分发送到操作。节是字符串变量。作用中的relativePath变量是动态的,由视图确定(通过视图传递参数)。太棒了!那个么你们得到了什么错误?并没有错误-我想要解决这个问题的方法。passin字符串变量从view到Controllerm的解决方案我首先想到的是学会编码……也就是说,如果要将多个变量作为
ActionResult
的参数传递,则需要在routes.config
文件中定义自定义路由
[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;
}