views:

413

answers:

4

I'm working with my ASP.NET development team to try and create "better" (i.e. cleaner) HTML when rendering pages. At the moment, .NET has a nasty tendency to do things like dump JavaScript into the page, making it a mandatory requirement on form controls and not allowing forms to work when JS isn't available. In some instances, we're struggling to overcome this without having to add a notable chunk to development time estimates.

I've worked with MVC before - via Struts in Java - and found that in that instance, I was able to keep HTML pages exactly as I'd wanted them to be. (This viewpoint is based on the "best case" static HTML I typically developed beforehand, then handed over to the Java programmers to fill in the holes.)

This worked out really well and we were able to produce some of the "best" web pages from a CMS that I've seen. Could .NET MVC give me the separation I need, or would it be a false economy to put aside valuable development time to test this?

If .NET MVC isn't going to give me this fine-grained control over separation, any recommendations for .NET coding practices, libraries, etc. which might would be really helpful.

+3  A: 

Depending on the view engine you're going to use. yes.

But you can easilly check this by looking at the page-source for stack-overflow. It's not zen-garden but it's pretty clean.

Some more clarification:

The rendering of the pages is done by the view engine. You can use the standard view engine or existing ones like nVelocity or Brail, just like with monorail. http://www.chadmyers.com/Blog/archive/2007/11/28/testing-scottgu-alternate-view-engines-with-asp.net-mvc-nvelocity.aspx

As the view engine is responsible for creating HTML what comes out depends on your choice. But most view engines are better in this respect than vanilla ASP.Net

Mendelt
Could you be more specific / offer examples, please? I'm not an ASP coder, so I'm not sure what you mean. I'm trying to research alternatives to present to my team. Thanks in advance.
markedup
Thanks for the clarification and examples, much appreciated.
markedup
+5  A: 

The ASP.NET MVC Framework would give you a much more familiar separation. Because there is no viewstate, etc in the MVC Framework you won't have to worry about JavaScript being dumped into your pages. The only JavaScript calls you see will be ones that you manually add.

You can, for the most part, separate HTML / CSS / JS like you would in a different framework.

Ryan Lanciaux
Are there specific caveats I should be aware of?
markedup
Not really -- It's pretty straight forward if you're coming from the perspective of using the HTML and having the ASP.NET MVC framework fill in the holes. I would recommend looking at Stephen Walther's site : http://weblogs.asp.net/StephenWalther/ for a good deal of tutorials and http://asp.net/mvc
Ryan Lanciaux
Great, thank you.
markedup
+1  A: 

@Wrestlevania said:

any recommendations for .NET coding practices, libraries, etc. which might would be really helpful.

I try to maintain a high level of separation while coding in ASP.Net. I find that if I avoid the asp controls and stick as much as possible with basic html elements, I can avoid any situation where ASP.Net would be inclined to inject extra CSS or JS into my page. Example, use span in place of asp:literal, button in place of asp:button, etc.

The only ASP control I use is the repeater, which is used to create a table. Any functionality I need that would be similar to an asp control, I either implement myself in javascript, or use a framework like jquery.

Geoff
We're working around these sorts of limitations in part, but I'm encountering resistance (separate issue!) to ditching ASP controls entirely. I'm using jQuery for most JavaScript coding at the moment and, apart from ASP changing some IDs, it's working well. Thanks.
markedup
A: 

Asp.Net MVC will help you keep html/css/js separate in that it will present fewer features that would prevent you from keeping them separate.

For example Html helpers typically return just that: Html. From that point you are free to choose to keep all style information associated only by class attributes.

Consider also looking into the practices you usually follow with a library like jQuery. It's an excellent example of how to keep the scripted functionality entirely in your js and out of your html by applying the event handling behaviors to the elements on page load based on things like element type, class and id.

loudej