Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Want to pass the data inside "Var" to the view but I don´t know how to catch it into the view

What I have tried:

conn.Open()
                   sql = New System.Data.SqlClient.SqlCommand
                   sql.CommandText = "exec areas '" & user & "' "

                   sql.Connection = conn
                   reader = sql.ExecuteReader()

                   If reader.HasRows Then
                       reader.Read()
                       var = reader.GetValue(0)
                       var2 = reader.GetValue(1)
                       Session("UserName") = var2

                       Return View()
                   End If
                   conn.Close()
Posted
Updated 9-Apr-18 20:44pm
Comments
Bryian Tan 9-Apr-18 21:53pm    
What wrong with Session("UserName") = var2?
Member 13585404 9-Apr-18 23:28pm    
"Session("UserName") = var2" contains the user name(from my form) because I'm doing a login, the only thing I want to do is to show in mi view "var" because it has the department name of the user name.
Member 13585404 9-Apr-18 23:29pm    
I don´t know if I explained it well
Bryian Tan 9-Apr-18 23:44pm    
for simplicity, you can stick with Session variable,

dim dept = reader.GetValue(0)
Session("department") = dept
Member 13585404 10-Apr-18 0:03am    
It works! thank you

1 solution

You can use
ViewBag to pass the value from Controller to View
for example in the .vb file
VB
ViewBag.Title = "Put your page title here"

in the html or razor page or view
HTML
<h1>@ViewBag.Title</h1>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900