"Models.LoginViewModel" is a type that is not valid in this context

My code:

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

      

I am getting the error:

'@ sample.Models.LoginViewModel' is a type that is not valid in this context.

Please give any idea to solve my problem.

+3


source to share


3 answers


change code

@sample.Models.LoginViewModel

      

and

@model sample.Models.LoginViewModel

      



those.

@model sample.Models.LoginViewModel

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

      

Keyword

@model should be at the beginning of u, just specifying only the model name

+4


source


you are wrong

@sample.Models.LoginViewModel

      



insted of use

@model sample.Models.LoginViewModel

      

+4


source


The syntax is wrong, please change

@sample.Models.LoginViewModel

before @model sample.Models.LoginViewModel

+2


source







All Articles