0
下面的代碼可用。當執行上傳控件時,控制器會收到「測試值」值。在MVC視圖中,我需要將模型中的值從KendoUI Widget傳遞到控制器。
但是,我從該視圖中顯示的模型中獲取了需要發送的關鍵值,而不是硬編碼文本。
注意。這是一個網格彈出編輯器中的自定義模板。
Widget ViewBag.Title =「Test Value」;
@(Html.Kendo().Upload()
.Name("files")
.TemplateId("fileTemplate")
.Async
(a => a
.Save("Save", "OpenRecords"), new { MyRequest = ViewBag.Title })
.AutoUpload(true))
)
控制器
public ActionResult Save(IEnumerable<HttpPostedFileBase> files, string MyRequest)
{
// The Name of the Upload component is "files"
if (files != null)
{
foreach (var file in files)
{
// Some browsers send file names with full path.
// We are only interested in the file name.
var fileName = Path.GetFileName(file.FileName);
var physicalPath = Path.Combine(Server.MapPath("~/App_Data"), fileName);
// The files are not actually saved in this demo
file.SaveAs(physicalPath);
ViewBag.FileName = fileName;
//return Content(physicalPath);
}
}
// Return an empty string to signify success
return Content("");
}