我有一个问题。 我使用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