I am new to MVC and Entity Framework, and would like some assistance in passing data to a model so that I can make my view a strongly typed view and get the information out as I need.
In the about action in the home controller i want to pull out data from my SiteContent table that is for the About Page
var sc = db.siteContents.Where( x => x.Page == "About").ToList();
return View(sc);
A couple of questions I have around this, is first, how do I get this into my Model SiteContent
public class SiteContent
{
public int ContentId { get; set; }
public string ContentType { get; set; }
public string Page { get; set; }
public string ContentHeader { get; set; }
public string Content { get; set; }
public DateTime OriginalPostDate { get; set; }
public DateTime UpdatePostDate { get; set; }
public string ImageFileName { get; set; }
public bool ContentReleased { get; set; }
}
I am uncertain on how I should proceed from here.
The from here I would like to use a strongly typed view to get the data by using my model.
Any and all help very much appreciated.
Thanks
Simon
SiteContent(which is what you currently have) of a singleSiteContentobject?SiteContentthe model used in yourDbContextor is this a POCO? Also, you're pulling a list (.ToList); did you mean to grabSingleOrDefault()?IEnumerable<SiteContent>as a model for your view.