使用mvc4,我有jquery调用上传操作 如果我用无参数调用方法(上传)它可以正常工作
使用操作="上传"
但我想传递参数,所以我尝试这个并且不能正常工作: 的行动="上传ID =&#39?; + data.record.ID +'"
如何使用动作传递参数? 在这里我的代码:
UplodedFiles: {
title: 'Uploded Files',
type: 'file',
input: function (data) {
return '<form target="iframeTarget" class="formUploadFile" action="Upload" method="post" enctype="multipart/form-data"> <input type="file" onchange="this.form.submit()" name="myFile"/> </form> <iframe class="upload-iframe" style="display: none;" src="#" name="iframeTarget"></iframe>';
},
list:false,
控制器:
[HttpPost]
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Upload(int id)
{
string upload_dir = Server.MapPath("~/app_data/Uploded/");
foreach (string f in Request.Files.Keys)
{
if (Request.Files[f].ContentLength > 0)
{
//System.IO.File.SetCreationTime(Server.MapPath("~/App_Data/Uploded/" + Request.Files[f].FileName), DateTime.Now);
Request.Files[f].SaveAs(upload_dir + System.IO.Path.GetFileName(Request.Files[f].FileName));
using (ProjectContext ProjectContext = new ProjectContext())
{
var p = _db.Projects.Find(id);
p.UplodedFiles += Request.Files[f].FileName + '#';
ProjectContext.SaveChanges();
}
}
}
return RedirectToRoute(new { Action = "Index", Controller = "Projects" });
}