Posts

Showing posts from July, 2012

A Very Simple ViewModel Example

Image
I'm currently working on a blog website app in ASP.NET MVC as a pet project. I'm not intending to use this new app instead of Blogger, but rather am doing it as a creative exercise. During the course of this project, I found the need to make use of the MVVM (Model View ViewModel) pattern. In this particular scenario, my implementation of MVVM was very simple, but extremely useful. In this blog post, I'll explain why I needed it, and how it came in handy. The App As I mentioned, my blog app is being written in ASP.NET MVC. I have a BlogPostController class that is used to coordinate the creation, editing, deleting, and retrieving of blog posts. The actual data operations are performed by a repository class that the controller calls. And, of course, the data is displayed and collected via views. The Data Model I'm using a SQL Server database with an Entity Framework data model. Among the tables/entities in my data model are BlogPosts and Tags. Tags are descriptive