Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MVC - Am I on the right track 1

Status
Not open for further replies.

noodle22

Programmer
May 8, 2008
23
I am trying to set up an MVC based web site but I have very little experience with this pattern and am not sure that I fully understand it. I'm pretty sure that I am not doing this right so am I on the right track here?

My Model - A bunch of data objects populated directly from the database (using nhibernate). To get values from this model, I have a bunch of data accessor classes (ie UserDA is used to get a single user, all users, users with certain attributes, etc). Each data accessor has two interfaces, the first one is the model interface (ex IUserModel) and is used to get data. The other is a controller interface (ex IUserController) which is used to save data.

Since I am using a webpage and since my model is basically just getting/saving data to a database, I am not implementing any sort of observer pattern (at least not yet).

View - Is a webpage that has an instance of both IUserModel and IUserController. It uses the IUserModel to populate the page and IUserController to save changes in the database. The view does contain code for populating certain data objects before saving (should that be in the controller?)

This is confusing for me because

a) really, the model and controller code is in the same class (those that access the db)

b) I could in fact access both the model and the controller from any class by just doing IUserModel model = new UserDA() or IUserController controller = new UserDA(). I don't really have any sort of class that manages the creation/assignment of controller and model interfaces.
 
Also, if anyone has any examples of classes (ie just the name and description) that I should be using in a database driven website that implements the MVC pattern, please feel free to post.
 
take a look at how MS MVC and MonoRail manage webpages. this is a true MVC implementation.

controlers direct the flow of the presentation. A user resquests a controler (usually determined by the URL). the controler is initiated and accesses the model.
any output from the model is placed in a container which is passed to a view. the view renders the contents of the container.

in this scenario the view has no knowledge of the model's purpose, strucuture or interaction. it only knows to take item(s) in the container and display them using HTML.

the controler doesn't know what the output looks like, only what information is required of the view and what view to render.

the model doesn't know how it will be presented. it is only responsible for managing the interactions between domain objects.

an ASP.Net MVC is a drastic depature from webforms. there is no sense of postback, view state serves no purpose and the web page is not event driven.

infact, MonoRail does not use webforms at all. it uses a templating engine (Brail I think) there is no code behind, postbacks, view state or server side controls. pure html and the contents of the container. Looks alot like php/asp 3.0.

MS MVC allows you to inject any type of view engine you want. the default is WebForms. this gives you the ease of data binding and serverside controls. but comes with the viewstate and autogenerated client id tax.
it would also be tempting to mix web form events with the MVC which defeats the purpose of MVC.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Hope you didn't think I forgot about you. I've actually been trying to get MVC up and running since you suggested it. I just got it to work yesterday. Seems like it might be an easier way to try to implement an MVC website compared to trying to figure out how to do it by myself.

Thanks
 
ok, just to follow up here. I have been using MS MVC for about almost a month now. It was pretty easy to transfer what I had done before into the new format. I feel like my code is much better organized now and far simplier to maintain.

I am curious how MS MVC compares to MS web client software factory ( It seems to incorperate an MVP pattern, is past the preview stage, and already supports AJAX (however, after working with AJAX for a bit, I will be happy to switch to silverlight and not have this mixture of javascript & C# modifying my interface)
 
MS MVC supports ajax if you use an ajax library like prototype or jquery or the client MS AJAX library. it wouldn't work with MS AJAX server controls because they are aware of (require?) postbacks, which don't exist in an implementation of MVC.

I'm not fimilar with websf. I know David Hayden has blogged about this framework. He seems to favor the M$ projects over other 3rd party frameworks.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top