我们可以在 MVC的文件中传递会话信息吗?,c#,asp.net-mvc,ado.net"/>

首页 > 解决方案 > 我们可以在 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");
        }

标签: c#asp.net-mvcado.net

解决方案


推荐阅读