tags:

views:

113

answers:

3

In my web application I have a treeview with documents. The NavigateUrl of a treenode looks like this: viewDocument.aspx?id=1&doctype=type. In the load event of ViewDocument.asp.cs i check whether id and doctype are set. If so, check doctype has a valid value and check the id is a number. After that, i create a document object. Then i call it's Load(int id) function which will load all the data in the object. If the id doesn't exists in the database the return value is false, otherwhise true.

Is it possible to use MVC pattern? And if so, how do i start?

+2  A: 

There is an official ASP.NET MVC framework. Check it out here. You can read up the tutorials there to get you started.

Razzie
@Razzie: This doesn't really address the issue according to his needs...
casperOne
True, but the question is a very broad one (too broad imho). I think it wouldn't hurt to start reading up on some tutorials, eventually to return here with more specific questions. Still, I applaud you for the more detailed answer. +1
Razzie
His question seems to call for a code answer about how to specifically implement something - but I think the underlying issue is more generally related to what MVC is and what it can do.
+2  A: 

It is, but MVC is the second issue you have to address.

It would make sense if you used URL rewriting here to rewrite your urls into this template:

documents/type/id

Here is a good blog post on how to enable URL rewriting for your site hosted in IIS7:

http://blogs.iis.net/bills/archive/2008/05/31/urlrewrite-module-for-iis7.aspx

Once you have that in place, MVC is an EXCELLENT candidate for handing this scenario. You would simply declare a route with this pattern:

{controller}/{action}/{id}

The controller would be a class (most likely, DocumentsController), the action would be the type in this case. You don't have to use that, you could use a type, but then you would have to set a default action when setting up the route. Finally, the id would be a parameter into the method that is specified by action.

casperOne
At this point it sounds like acracadabra. But i'm installing MVC now and hopefully after that i will understand your post :)
Martijn
@Martijin: At some point, you should do some URL rewriting. I think that MVC is important for this, but the shape of your URLs now don't really support it, so keep that in mind.
casperOne
+1  A: 

Start by looking into what the MVC pattern is and what it buys you. To really use the MVC pattern, and not just superficially implement some framework, you will need to get your hands around the concept rather than just reading through the framework's API.

Some of the things MVC can buy you (though not exhaustive):
- decoupling actual display from flow control and business logic
- all the -ity's:
modularity
readability
maintainability
testability

Though to get all these advantages, you have to understand the MVC concept and apply it correctly, not just arbitrarily include a framework in your project and then expect everything to go right.

Here's a good starting point for MVC: http://en.wikipedia.org/wiki/Model-view-controller