繁体   English   中英

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; }
}

这是控制器的Update操作:

[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 });
           }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM