I'm new to MVC 3 and the Devart LinqConnect product and hit a little issue, namely due to my lack of understanding I think.
What I'm trying to achieve is a working example that I can build from to help with the learning curve.
In this example I've set myself a goal where:
Using VS 2010 and latest version of Devart LinqConnect Pro.
1) create a function in a model to pull back a list of names from a table.
2) pass the list from the model to the controller and from the controller to a view
Those of you reading this that are seasoned programmers might already be asking why am I taking the above approach. If my understanding is correct what I'm doing is putting my business logic in a new model under the models folder to conform with the mantra around seperation of concerns. So in my mind the correct process is to have the bulk of my web application logic and functions in my model folder, the controllers to direct my user and the views to render out my data (hopefully that is the right approach).
So I have a model called ContactModel.cs under the Models folders with the following code:
Code: Select all
public class Contacts
{
public Contacts()
{
MyDBDataContext db = new MyDBDataContext ();
Table<TBLCONTACTNAME> TBLCONTACTNAMEs = db.GetTable<TBLCONTACTNAME>();
var MyContacts =
from c in TBLCONTACTNAMEs
select c.FirstName;
}
}
And this is where I've got stuck. My next goal is to get the HomeController.cs under the controllers folder to use this function to get a list back and pass it to a view to render the data. Something like the below in the HomeController:
Code: Select all
public ActionResult ShowContacts()
{
Contacts s = new Contacts();
return View("ShowContacts", s);
}
Code: Select all
<h2>Show Contacts</h2>
<fieldset>
<legend>Contact List</legend>
@foreach (var item in Model)
{
@Html.Encode(item.FirstName)
}
</fieldset>
Code: Select all
return MyContacts.ToList();
I'm pretty sure the answer is easy, and I just need a working example / guidance that I can follow which should get me moving again. I can get the data OK, it's now just a case of being able to use it in a function that I can pass to a view to output on screen.
Many thanks in advance to any and all replies )