This Question have 3 answers right now.

Will .NET MVC give me the HTML/CSS/JS separation I need?

Question!

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.



Answers

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.

By : loudej


@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.

By : Geoff


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

By : Mendelt



Single-page display, multi-page print problem

HTML Checkboxes in select list

Another “is ASP.NET MVC right for me?” question

Relative Paths in Javascript in an external file

Best way to size an element to the size of another element

Loading jQuery from Google or locally if not online

Links are being printed besides the text

Javascript, HTML and CSS Grid

Any suggestions for a responsive grid that will adapt text size and layout for different browsers?

Problems with creating a box and with a number under it with razor using foreach

Drop down list width fit selected item text

What is the best practice to include js/css files in an enterprise application framework?

Highlight/Unhighlight ONE row in a column

Execute Javascript if element with specific CSS class exists

Truncating text inside a div [duplicate]

dropdown hide behind mootools silder

Prevent button effect on html input and button tag

Best way to block out UI elements when editing data

how to set background-image

Video about Will .NET MVC give me the HTML/CSS/JS separation I need?