Operation MVC

Posted by Ken Lovely, MCSE, MCDBA, MCTS on Geeks with Blogs See other posts from Geeks with Blogs or by Ken Lovely, MCSE, MCDBA, MCTS
Published on Mon, 17 May 2010 01:26:21 GMT Indexed on 2010/05/17 2:30 UTC
Read the original article Hit count: 471

Filed under:

It was time to create a new site. I figured VS 2010 is out so I should write it using MVC and Entity Framework. I have been very happy with MVC. My boss has had me making an administration web site in MVC2 but using 2008. I think one of the greatest features of MVC is you get to work with root of the app. It is kind of like being an iron worker; you get to work with the metal, mold it from scratch.

Getting my articles out of my database and onto web pages was by far easier with MVC than it was with regular ASP.NET.

This code is what I use to post the article to that page. It's pretty straightforward. The link in the menu is passes the id which is simply the url to the page. It looks for that url in the database and returns the rest of the article.

 

DataResults dr = new DataResults();
string title = string.Empty;
string article = string.Empty;
foreach (var D in dr.ReturnArticle(ViewData["PageName"].ToString()))
{
title = D.Title;
article = D.Article;
}

public

 

List<CurrentArticle> ReturnArticle(string id)
{
var resultlist = new List<CurrentArticle>();
DBDataContext context = new DBDataContext();
var results = from D in context.MyContents
where D.MVCURL.Contains(id)
select D;foreach (var result in results)
{
CurrentArticle ca = new CurrentArticle();
ca.Title = result.Title;
ca.Article = result.Article;
ca.Summary = result.Summary;
resultlist.Add(ca);
}
return resultlist;}

 

 

© Geeks with Blogs or respective owner