Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...This was the ONLY place that I could find information that I could use to resolve the problem. So thanks once again to member TomSark and the SQL forum!..."

Geography

Where in the world do Tek-Tips members come from?
noodle22 (Programmer)
8 May 08 18:17
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.
noodle22 (Programmer)
8 May 08 18:18
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.
Helpful Member!  jmeckley (Programmer)
9 May 08 15:29
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.

noodle22 (Programmer)
15 May 08 13:45
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
noodle22 (Programmer)
12 Jun 08 11:42
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 (http://www.codeplex.com/websf).  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)  
jmeckley (Programmer)
12 Jun 08 11:56
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.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close