Sign up ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

I'm working on a ASP.NET MVC 4 web application. A requirement for this app is that pages should be able to work even if user has javascript disabled. Which is the best approach to do this? Should I create 2 views ?

  1. one view using jquery, javascript code for radio buttons postbacks, etc.

  2. onew view with just HTML and no javascript.

Is this correct or a good practice?

How could I display a message saying that user needs to enable javascript if wants to see a specific page?

Thank you in advance.

share|improve this question

closed as primarily opinion-based by Mike Cheel, Shaunak D, ArK, hwnd, Ivan Ferić Jul 3 '14 at 6:22

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.

    
In my point of view....in your views you only have to change the way in your controller methods should be access....if you have js enabled, you can call them with ajax...if not, then with direct action on your forms pointing to your controller method... – Hackerman Jul 2 '14 at 19:17
2  
You should look into the technique of Progressive Enhancement. Essentially make your application work without JavaScript, then layer the JavaScript features on top of that. – jmoerdyk Jul 2 '14 at 19:17
    
for example, how could I do a radio button postback without javascript? is it possible? – Alberto Montellano Jul 2 '14 at 19:28

1 Answer 1

up vote 4 down vote accepted

The terms you're looking for are "graceful degradation" and "progressive enhancement."

The correct approach is not to make separate views, no. After all, how is your server-side code going to know which view to present? It's really not the server-side code's business whether or not the client has JavaScript enabled. Instead, the correct approach is to create a single view which works in any necessary scenario.

For example, let's say you want to post a form via AJAX and display a message after it's been posted. Clearly you can't do this without JavaScript. So what you would do is create a normal page with a normal form which posts to a server-side action and returns the same page with the message displayed. Then you'd write some JavaScript code to attach to the form's submit event, cancel event propagation, make an AJAX request to a server-side action (perhaps a different action, or perhaps the same one and just parsing the result from the page... though the latter seems like a heavier operation than necessary), and display the message as a result of the response.

This same page will work with or without JavaScript. Those without JavaScript will simply post the form and reload the page. Those with JavaScript will have that functionality "overridden" by the JavaScript code to produce new functionality.

The goal is that all functionality of the application is accessible without any JavaScript. Then JavaScript is used to "inject" its functionality and override the non-JavaScript functionality so that if it's enabled the user has a somewhat better user experience.

How could I display a message saying that user needs to enable javascript if wants to see a specific page?

That seems to entirely conflict with the requirement that "pages should be able to work even if user has javascript disabled." You could use noscript tags I suppose (I haven't seen those in years, not sure if they were ever technically standard), or even just show the message by default and hide it with JavaScript as the page renders (thus, those with JavaScript wouldn't see it). But either way, that means you would have functionality which requires JavaScript, which is contrary to the requirement.

share|improve this answer
    
great answer @David thank you very much – Alberto Montellano Jul 2 '14 at 19:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.