& # 39; Models.LoginViewModel& # 39;是一个类型,在给定上下文中无效

本文关键字:无效 类型 上下文 LoginViewModel Models 一个 | 更新日期: 2023-09-27 17:49:46

我的代码是:
@sample.Models.LoginViewModel
@{
    string user = Session["users"].ToString();
}
@{
    ViewBag.Title = "Home Page";  
}

我得到错误:

' @sample.Models。LoginViewModel'是一个类型,它在给定的上下文中无效。

请给我一些建议来解决我的问题

& # 39; Models.LoginViewModel& # 39;是一个类型,在给定上下文中无效

change code

@sample.Models.LoginViewModel

@model sample.Models.LoginViewModel
ie

@model sample.Models.LoginViewModel
    @{
       if(Session["users"] != null)
       {
        string user = Session["users"].ToString();
       } 
    }
    @{
        ViewBag.Title = "Home Page";  
    }

@model关键字应该放在开头,你只需要指定模型名

你做错了

@sample.Models.LoginViewModel

代替

@model sample.Models.LoginViewModel

你的语法错误,更改

@sample.Models.LoginViewModel@model sample.Models.LoginViewModel