Geeks With Blogs
A Developer's Expedition www.kenl.net

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;}

 

 

Posted on Sunday, May 16, 2010 2:26 PM | Back to top


Comments on this post: Operation MVC

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Ken Lovely, MCSE, MCDBA, MCTS | Powered by: GeeksWithBlogs.net