Kendo UI-通过网格中的上传小部件将图像路径存储在数据库中
Kendo UI - Store image path in database through upload widget in grid
我可以上传图像并将其保存到文件夹中,但唯一的问题是将路径存储在SQL表中。我想将照片路径保存到数据库中,以便在其他地方显示。这就是我到目前为止所拥有的。
物品类别:
public class Item
{
public int ItemId { get; set; }
public string ItemName { get; set; }
public string Photo { get; set; }
}
以下是控制器的更新操作:
[HttpPost]
public ActionResult Update(item, HttpPostedFileBase files)
{
if (files != null && files.ContentLength > 0)
{
string fileName = Path.GetFileName(files.FileName);
var physicalPath = Path.Combine(Server.MapPath("~/Content/uploads"), fileName);
item.Photo = physicalPath;
files.SaveAs(physicalPath);
return Json(new { Photo = fileName }, "text/plain");
}
return Json(new[] { item });
}
带有上传小部件集成的网格示例:
http://jsbin.com/safog/1
尝试使用下面的代码,它可以正常工作。
[HttpPost]
public ActionResult Update(item, HttpPostedFileBase files)
{
if (files != null && files.ContentLength > 0)
{
string fileName = Path.GetFileName(files.FileName);
var physicalPath = path.Combine(HttpContext.Request.MapPath("~/Content/uploads"), fileName);
item.Photo = physicalPath;
files.SaveAs(physicalPath);
return Json(new { Photo = fileName }, "text/plain");
}
return Json(new[] { item });
}
相关文章:
- 复制图像路径以单击它
- 如何使用jquery将base64图像路径转换为真实路径
- 滚动页面时的弯曲图像路径
- Gulp bower图像路径
- Symfony2-Javascript文件中的图像路径
- 将图像内容而非图像路径存储在mongodb中
- MVC5 和 Javascript 相对图像路径混淆
- 简单的图像滑块Javascript图像路径在IE 6中不起作用
- 从表单中派生要使用javascript对象加载的图像路径
- 如何设置与CKEditor一起使用的图像路径
- AngularJS/JavasScript中的本地图像路径
- 将 grunt-usemin 与动态生成的图像路径一起使用
- 如何使用 php 将捕获的图像路径存储在 mysql 数据库中
- 需要 Rails 应用程序中本机 HTML 的图像路径
- Javascript 无法解析正确的图像路径,当使用 URL 路由在 ASP.Net 中请求页面时
- 在 jquery 中为内联 css 构建图像路径的最佳方法
- “电子邮件”在电话间隙中共享的图像路径
- 使用带有错误图像路径的 jQuery 加载打开的页面
- 推送整个网站数组中的所有图像路径
- 使用一个javascript字符串作为css背景属性的图像路径