How to organize views, partial views and their view models?
I'm developing in asp.net mvc2. I am beginning to create a lot of views and partial views, for most of which I've had to create开发者_Python百科 a view model. This is looking like soon it's going to become unmanageable to remember what view goes with what model. I've tried to use inheritance in my view models as much as possible.
I'm wondering how others manage this in their projects?
I place my PV's inside a PV folder within the Views folder.
so Views/Home/PartialViews
;
I then register that path in my global.asax file;
public static void RegisterViewEngine()
{
ViewEngines.Engines.Clear();
WebFormViewEngine viewEngine = new WebFormViewEngine();
viewEngine.PartialViewLocationFormats = (new[] {
"~/Views/Shared/PartialViews/{0}.ascx",
"~/Views/{1}/PartialViews/{0}.ascx"
}).Concat(viewEngine.PartialViewLocationFormats).ToArray();
ViewEngines.Engines.Add(viewEngine);
}
I'm also these days leaning towards putting the FormViewModels within the views folder.
/Views/Home/IndexFormViewModel.cs
The above is recent as before this I put them in a Models project but found that sometimes I could end up with a cyclic reference situation with my Model and DataRepository.
精彩评论