Last post Jun 30, 2017 05:27 AM by Jean Sun
Jun 30, 2017 12:25 AM|PhillD|LINK
I am new to MVC and C# but have been working with VB.NET and SQL for 10+ years. I am trying to build an MVC website in C# to somewhat future proof the site and ultimately, learn a new programming language and framework (if that the right term for MVC??)
Unfortunately, I am NOT having much success and I keep getting tripped up over the million different ways of doing the same things and my lack of understanding of C# syntax. I am also writing this site for my employer and cannot spend great amount of time
making little progress.
With that said, could someone please get me started with a great basic example of how I would load data from an entity table and load it into a view within MVC. I have watched youtube video's read articles and searched this site. All seem to lead to fragmented
information or responses that say...go read this generic tutorial that doesn't really help you.
I've seen some uses create the entity model and then create entire new classes to pass data from entity to their custom class before loading it, I've seen people pulling data straight out of entity and then use LAMBDA. I've even read articles from people
who want to compare programming to Platos and then go off about domain models in way too much detail.
I just need help getting data from a database table into an MVC web page without 100000 lines of code. That would be a really good start for me.
Can someone help?
Jun 30, 2017 12:44 AM|PhillD|LINK
I should probably add that I have spent some time learning about MVC too and I do understand the basic premise of Model, View Controller and I do have an entity model created in the model folder with a single table.
Jun 30, 2017 03:03 AM|Jean Sun|LINK
The following link shows basics of using Entity Framework 6 to display and edit data in an ASP.NET MVC 5 application. Please take it as reference.
When I start to learn MVC, the above link helps me a lot.
When you meet some error or problem, you can post your issue in the forum. So we can discuss about this issue and learn how to troubleshoot it.
Jun 30, 2017 05:08 AM|PhillD|LINK
Jun 30, 2017 05:16 AM|PhillD|LINK
Jun 30, 2017 05:27 AM|Jean Sun|LINK
The DAL is the data access layer, we put the EF DBContext inside it. Then we can use it to communicate with the database using just a few lines of code like the following.
Use the DAL is aimed to loose couple. To keep the code you use to pull data from your database separate from business logic and presentation code.
var db = new DAL.DbContext();
public ActionResult Index()
var records = db.Model.ToList(); //Retrieve records from database
return View(records); //Pass the records to the view and return the view page
Then in your view, you need to declare the data type you are passing from Action using @model. In above code you are passing list of Model to view, so you should declare the data type like the following in your view page: