Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialMohamed Monir
22,362 PointsMove list of Data to View MVC
i use this code to git Data fro DB in model public string DBconect = ConfigurationManager.ConnectionStrings["DB"].ConnectionString; public void add() { using (SqlConnection con = new SqlConnection(DBconect)) {
SqlCommand cmd = new SqlCommand("getRoom_empty", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
}
}
}
how to move data to View Page
1 Answer
Jon Wood
9,884 PointsIf you're not sure how to get data from the SqlReader
, check this StackOverflow post.
I don't know how the rest of your project looks, but if you want to use the data in a view, you could map the data to a model class and use that in your view. Typically, you'd call data methods from the controller via a repository and use the results from there to pass into your view.
Hope that helps, but let me know if you need more details.
Mohamed Monir
22,362 PointsMohamed Monir
22,362 Pointsi know how use datareader but i ask to move Dataset from Model To View Page
Jon Wood
9,884 PointsJon Wood
9,884 PointsRight, just pass the model into the view, like this -
View(model)
. You can strongly type the model on the view page with@model ModelType
.