c# - 我们可以在 MVC的文件中传递会话信息吗?
问题描述
这是 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" />
}
欢迎控制器//
public ActionResult Index()
{
string s = (string)Session["Profile_pic"];
ViewData["Img"] = s;
return View();
}
登录控制器()//
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");
}
解决方案
推荐阅读
- javascript - 我可以使用带有 && 作为分隔符的 jquery 多个 id 选择器来获得所有 id 都满意的结果吗?
- spring - Eclipse 的 Spring Tool Suite 插件删除了我的 WEB-INF 文件,我收到很多错误
- lua - 需要帮助在 Lua 中编写范围查找代码
- node.js - 如何修复代码,我的验证使 mocha 在测试过程中行为不端
- javascript - 在单击按钮时更改变量的值
- arrays - Excel - 使用带有数组的 CountIFS 来排除结果
- database - ORA-39358: 导出转储文件版本 12.2.0 与目标版本 12.1.0.2.0 不兼容
- php - PHP - array_diff() 缺少一条记录
- kubernetes - 更改控制平面负载均衡器地址
- google-cloud-platform - 用于 Cloud Function 调用 Composer 的 Cloud Firestore 触发器