如何显示在图像控制的路径存储在数据库使用MVC的图像 [英] how to display an image in a image control whose path is stored in db using mvc

查看:309
本文介绍了如何显示在图像控制的路径存储在数据库使用MVC的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何可以显示图像控制的路径存储在数据库中的图像。
请为我提供样品code我已经得到数据库的路径,但我怎么能在图像控制显示英寸
这里是我的code

  [HttpPost]
    公众的ActionResult DisplayPic()
    {
        字符串username = User.Identity.Name;
        在Session.Query&LT VAR的getPath =从磷;登记>()
                      其中,p.Email ==用户名
                      选择p.Path;
        如果(getPath.Count()大于0)
        {
           //显示图片?        }        返回查看();
    }

查看:

  @ {
        ViewBag.Title =DisplayPic;
      }    < H2> DisplayPic< / H>
    @using(Html.BeginForm())   {
     &所述; IMG ALT =SRC =宽度=200HEIGHT =200/>
   }


解决方案

店面形象模型中的属性路径,并使用

 < IMG SRC =@ Url.Content(Model.ImagePath)ALT =图片/>

How can i display an image in image control whose path is stored in database. Please provide me with sample code i have get the path from database but how can i show in in image control . here is my code

   [HttpPost]
    public ActionResult DisplayPic()
    {
        string UserName=User.Identity.Name;
        var getPath = from p in Session.Query<Registration>()
                      where p.Email == UserName
                      select p.Path;
        if (getPath.Count() > 0)
        {
           //display pic???

        }

        return View();
    }

View:

     @{
        ViewBag.Title = "DisplayPic";
      }

    <h2>DisplayPic</h2>
    @using (Html.BeginForm())

   {
     <img alt="" src="" width="200" height="200" />
   }

解决方案

Store image path in your model property and use

<img src="@Url.Content(Model.ImagePath)" alt = "Image" />    

这篇关于如何显示在图像控制的路径存储在数据库使用MVC的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆