我有一個問題。 我使用Kendo UI for ASP.NET MVC爲我的web應用程序創建上傳功能。它運行良好,但問題是用戶在點擊上傳按鈕執行提交表單後無法看到他們上傳的文件,並導航到其他頁面。在這種情況下,我在Create View中放置了一個上傳器,並且在將文件上傳到服務器之後,我會將該文件的鏈接存儲到db中我模型的字段中,但它始終爲空值。這裏有人能給我一些建議嗎?非常感謝。這是我使用的代碼。 *控制器:Kendo UI上傳,上傳文件後如何獲取路徑url成功
[HttpPost]
public ActionResult Create(Model model)
{
if(ModelState.IsValid)
{
model.Url = Url;
Db.Models.Add(model);
Db.SaveChanges();
return RedirectToAction("Index");
}
return View(model);
}
public ActionResult Save(IEnumerable<HttpPostedFileBase> attachments)
{
// The Name of the Upload component is "attachments"
foreach (var file in attachments)
{
// Some browsers send file names with full path. We only care about the file name.
var fileName = Path.GetFileName(file.FileName);
var destinationPath = Path.Combine(Server.MapPath("~/Contents/files/"), fileName);
DestinationPath = destinationPath;
file.SaveAs(destinationPath);
}
// Return an empty string to signify success
return Content("");
}
查看
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<div class="editor-label">
Upload file
</div>
<div style="width:45%">
@Html.Kendo().Upload().Name("attachments").Async(async => async.Save("Save", "Model").AutoUpload(true)).Multiple(false)
</div>
<p>
<input type="submit" value="Create" class="k-button" />
</p>
型號
public string Url {get;set;}
不知道我理解你的問題。讓我解釋一下:在創建視圖中,您有一個異步Kendo上傳。用戶使用它來上傳文件。然後點擊查看保存提交表單。但保存的模型沒有指向上傳文件的鏈接。這是問題嗎? – 2013-03-06 07:32:57
是的,我不知道從哪裏獲取文件的鏈接以保存到Url。 – 2013-05-03 07:25:41