在图像中显示图像其路径存储在db中的控件。 [英] Display image in a image Control whose path is stored in db.

查看:82
本文介绍了在图像中显示图像其路径存储在db中的控件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在文件夹中上传了用户的个人资料图片,并使用MVC4将其路径保存在db中。

在我的视图中我有一个Image控件。我想显示用户的个人资料照片当他登录时。



将使用什么方法来显示图像。我在DisplayPic方法中从db获取图像路径

of a控制器



[HttpPost]

公共ActionResult DisplayPic(FileManagement fm)

{

string ipath;

string UserName = User.Identity.Name;

var getPath = from Session.Query< registration>()

其中p.Email ==用户名

选择p;

if(getPath.Count()> ;; 0)

{

foreach(getPath中的var imgpath)

{

ipath = imgpath.Path;

}

}



返回查看(fm);

}

< br $>


查看

@Model MvcMembership.Models.FileManagement

@ {

ViewBag .Title =DisplayPic;

}



DisplayPic



@using (Html.BeginForm())



{

< img src =/>

}



我可以将存储在ipath中的图像路径值传递给图像src吗?

任何帮助都将不胜感激。

I have uploaded profile picture of a user in a folder and saved its path in db using MVC4.
In my view i have a Image control.I want to display the profile pic of a user when he logins.

what method will be used to display image.I have get the image path from db in DisplayPic method
of a controller

[HttpPost]
public ActionResult DisplayPic(FileManagement fm)
{
string ipath;
string UserName=User.Identity.Name;
var getPath = from p in Session.Query<registration>()
where p.Email == UserName
select p;
if (getPath.Count()>; 0)
{
foreach (var imgpath in getPath)
{
ipath = imgpath.Path;
}
}

return View(fm);
}


View
@Model MvcMembership.Models.FileManagement
@{
ViewBag.Title = "DisplayPic";
}

DisplayPic


@using (Html.BeginForm())

{
<img src="" />
}

Can i pass value of image path that is stored in ipath to image src?
Any help will be appreciated.

推荐答案



Hi,
create 
ViewBag.Imagepath=yourpathvalue; //in controller.
Then in view,
<img src="@Url.Content(ViewBag.Imagepath)" />



希望它可以帮到你。

谢谢。


Hope it helps you.
Thanks.


这篇关于在图像中显示图像其路径存储在db中的控件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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