这是MVC中的注册表。我使用字符串作为数据库中的存储(例如:imgpath varchar(256)),并将图像上传到SOURCE文件夹的img文件夹中(例如:〜/ img / img_name.jpeg)。登录后,我将该信息作为会话变量传递并在img src中使用它?但是它不能为图像提供任何建议吗?
<img src="@Html.ViewData["Img"]" alt="IMG" height="250" width="250">
<img src="@HTMLContext.Current.Session["Profile_pic"]" alt="IMG" height="250" width="250">
CSHTML //
@if (Session["email"] != null)
{
<h1>Welcome @Session["email"].ToString()</h1>
<br /><br />
<img src="@Html.ViewData["Img"]" alt="img" height="150" width="150" />
}
WelcomeController //
public ActionResult Index()
{
string s = (string)Session["Profile_pic"];
ViewData["Img"] = s;
return View();
}
LoginController()//
using (DemoEntities db = new DemoEntities())
{
if (userdetail == null)
{
user.LoginErrorMsg = "Invalid Username or Password";
return View("Index", user);
}
else
{
Session["email"] = user.Email;
Session["Profile_Pic"] = user.User_image;
return RedirectToAction("Index", "FirstView");
}