How to use a Base ViewModel in Asp.net MVC 2
Posted
by Picflight
on Stack Overflow
See other posts from Stack Overflow
or by Picflight
Published on 2010-05-01T19:06:26Z
Indexed on
2010/05/01
19:17 UTC
Read the original article
Hit count: 296
asp.net-mvc-2
|viewmodel
As I familiarize myself with Asp.Net MVC, I am using MVC 2, I have noticed the use of a BaseViewData class in the Kigg project which I am unsure how to implement.
I want each of my ViewModels to have certain values available. Using an iterface comes to mind but I am wondering what the best practice is and how does Kigg do it?
Kigg
public abstract class BaseViewData
{
public string SiteTitle { get; set; }
// ...other properties
}
public class UserListViewData : BaseViewData
{
public string Title { get; set; }
// .. other stuff
}
In my WebForms application I use a BasePage that inherits from System.Web.UI.Page.
So, in my MVC project, I have this:
public abstract class BaseViewModel
{
public int SiteId { get; set; }
}
public class UserViewModel : BaseViewModel
{
// Some arbitrary ViewModel
}
Referencing the Kigg methodology, how do I make sure that each of my ViewModel that inherits from the BaseViewModel have the SiteId property?
What is the best practice, samples or patterns I should be using?
© Stack Overflow or respective owner