1

I have a simple view, without any Model in it, I want to display all course on it from course table and language list from languages table.

both table are not connected to each other, in webform we where using usercontrol to get the result, but in MVC I am not able to get the result we want.

any tutorial will be great.

Regards

4 Answers 4

1
  • You should query the database to retrieve those 2 collections.
  • Create a View Model object with 2 properties to hold the 2 collections.
  • Then pass that object to your view.
  • In the View create an HTML table for each collections

A ViewModel is class where you have exactly what you need in your view. In this case:

public class MyViewModel{
   public List<Course> MyCourses { get; set;}
   public List<Language> MyLanguages { get; set;}
} 

In your controller action, you can call the database logic you have to retrieve the collections, instanciate your viewmodel, and then pass it to your view.

0

you can make easily a model from your db and assign it to a grid via controller and finally show on your view page.

more: http://www.asp.net/mvc/tutorials/older-versions/models-(data)/displaying-a-table-of-database-data-cs

0

Have you tried the following links. There are plenty of tutorials on using EF with ASP.NET MVC http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc

0

Did you try ViewData? You cannot use it if you want to store huge data.. otherwise, using Modelbinding is the best way to display data on the view. Good luck?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.