How is the HTML on this site so clean? - html

I work with C# at work but dislike how with webforms it spews out a lot of JavaScript not including the many lines for viewstate that it creates.
That's why I like coding with PHP as I have full control.
But I was just wondering how this sites HTML is so clean and elegant?
Does using MVC have something to do with it? I see that JQuery is used but surely you still use asp:required validators? If you do, where is all the hideous code that it normally produces?
And if they arent using required field validators, why not? Surely it's quicker to develop in than using JQuery?
One of the main reasons I code my personal sites in PHP was due to the more elegant HTML that it produces but if I can produce code like this site then I will go full time .net!

One of the goals of ASP.NET MVC is to give you control of your markup. However, there have always been choices with ASP.NET which would allow you to generate relatively clean HTML.
For instance, ASP.NET has always offered a choice with validator controls. Do you value development speed over markup? Use validators. Value markup over development speed? Pick another validation mechanism. Your comments on validators are kind of contradictory there - it's possible to use ASP.NET and still make choices for markup purity over development speed.
Also, with webforms, we've had the CSS Friendly Control Adapters for a few years which will modify the controls to render more semantic markup. ASP.NET 3.5 included the ListView, which makes it really easy to write repeater type controls which emit semantic HTML. We used ASP.NET webforms on the Microsoft PDC site and have kept the HTML pretty clean: http://microsoftpdc.com/Agenda/Speakers.aspx - the Viewstate could probably be disabled on most pages, although in reality it's only a few dozen bytes.

You were on the right track. It is the fact that they are using the ASP.NET MVC web framework. It allows you to have full control of your output html.

The ASP.NET MVC Framework is an alternative to the normal "web forms" way of doing ASP.NET development. With it you lose a lot of abstraction, but gain a lot of control.

Yes - MVC doesn't utilize the ASP.NET view state junk.

Related

HTML Layout/Templating

I am building a website where i'm looking to create html templates which contain placeholders where i'll be able to inject pages/content, menus, etc.... I really like AngularJS which has good support for this but am thinking that it might be a bit of an overkill for what i'm building. There is a chance some parts of the application will eventually be ripped out and run standalone and so dont want to tie the html/javascript to a library which requires so much framework specific syntax. Are there any other, simpler libraries, that will allow me to do this? thanks in advance
/Eric
KnockoutJS is pretty lightweight and also includes a templating feature.
I wouldn't just dismiss angularjs because it seems like a heavy framework. There are very simple ways to use it without using any of the "advanced" features like routing, creating services, creating directives, etc. You can simply have a controller and use the built in directives to do a lot of powerful things on a single page. Angular is also pretty small and is easily bootstrapped with the ng-app tag anywhere in your DOM.

Is there a convenient way to prototype future structure of View layer of MVC framework (Rails or like) on pure HTML?

My "Rails friends" have a situation when their UI designer is beginning his work on prototyping UI screens on his own - their Rails programmer is busy and is going to join this work later, probably much later.
I know, it is easy to ask UI designer the learn Rails rendering mechanism, so he could begin prototyping on Rails, but I am interested,
is it possible to setup views structure using partials (reusable pieces of HTML views) using just pure HTML, without any ruby code inside?
The only approach I see is to use SSI. Are there any other options?
What is needed is simply a possibility for one html-file could have a string like
<whatever include other.html ...>
which would include the contents of other.html inside its body.
This way, a future project can be divided logically on changeable/nonchangeable parts without any Ruby/Php code for partials.
UPDATE 1
The quoted wiki page about SSI has Client Side Includes section that suggests using object tag which seems to work
<object type="text/html" data="test.html"></object>
One suggestion is to use Sinatra, which is a simple and quick web framework for static sites.
It's easy to start using Sinatra even for a beginner. However, even if the UI man doesn't know and don't want to study any coding, he can still utilize it by planning the partial names and ask the developer to setup it for him. All he need to do later is to fill each blank templates and add JS CSS image assets.
Benefit of Sinatra:
Friendly to static sites
Simple to use
Lots of templating language to use, same as Rails
The partials/templates can be ported to Rails later with zero efforts!!!

HTML - writing vs generating code

I've had the chance to work with very different types of frameworks for web development. Somehow I can see that every framework tries to avoid me writing pure HTML code.
For example Spring has it's own tags, Struts comes with it's own tags also Zend and Codeigniter (PHP) have form helpers.
Does this mean I shouldn't just write HTML code myself or that it's not recommended? SHould I be using them? because they don't seem that intuitive, easy to manage and time saving as they intend.
You need to write your own HTML (and CSS) to define the overall structure and layout of your website design. Don't confuse this with time-saving features that eliminate the need to write repetitive HTML, such as form inputs and navigation menu items.
For example, under ASP.NET MVC you still need to get the bulk of your HTML into a MasterViewPage or Razor Layout, but when it comes to writing all of the form inputs you just need to put <%= Html.TextBoxFor( m => m.FirstName ) and it handles the rest, which saves you the trouble of writing boilerplate HTML for the <input /> element. It also helps avoid bugs (if you forget a name="" or `id=""`` attribute, for example, but in some frameworks it's essential to get reliable round-trip form data working.
I suggest you to manage your code by yourself if you don't have VERY good tools for generate it (for example Razor in ASP.NET MVC) which can do your code cleaner and more intuitive. In your case if You use Zend i suggest you to write your html in normal sites and only use generator for forms with Zenf_form. Becouse it is great.
Generated code services I have used generate ugly code that is hard to sift through at a later date.
writing the code and HTML yourself makes for a better structure and will not effect the way its run if that is what you are worried about and these languages are set to a standard.
Recommendation is to write the code where you can and generate code in areas you dont (or learn how to code it before you attempt it in test sheets).
I think it is a case by case basis.
These frameworks help you get rid of boilerplate code and write cleaner applications. You might also avoid some security problems by using them and you respect MVC.
There might be a performance penalty though so if you write a small application or you have certain requirements in speed you might be better without (some of) them.

asp.net mvc 4 vs JavaScript templates

I've been struggling in deciding what direction to go with in regards to the best approach for rendering content to the browser: server side using razor or client side using JSON data and some form of templating (jsRender, loadJson, etc.)
Here's a great article on using client side templating with asp.net mvc:
jQuery Templates/View Engines in ASP.NET MVC
ASP.Net MVC 4 has some great toys (WebAPI). I can see creating a suite of WebAPI functionality for delivering JSON data that can be used on traditional web pages and even mobile pages. Really cool stuff.
Then I look at what options you have going with a traditional ASP.Net MVC approach. You have layouts, can take advantage of automatic bundling/minification of JS/CSS files (more ASP.Net MVC 4 goodness), robustness of having ASP.Net MVC available at your fingertips. Really cool stuff.
So, my question is how do you make decisions on which direction you should go architecturally? I suppose you can have a mix bag of approaches within your site, but that becomes a maintenance issue. Going total JavaScript Templates and consuming JSON data from a service is a super clean separation of concerns, but it seems you loose out on a lot of the goodness that ASP.Net MVC offers like routing.
What's the best approach for balancing all of the options available to us?
This is a bit of a general question, so a general answer is that you should stick to the approach that makes you most productive/gets the job done. Either approach works but of course has tradeoffs. However those usually don't matter that much unless you reach really big scale (e.g. Twitter recently annonced it will move back to server-side rendering for performance reasons). If you're already familiar with MVC and you're working against a deadline - stick to that. If you have more time or want to learn a new technique - go with what looks interesting.

Is HTML5 compatible with C#?

I am having trouble finding a clear answer on this one. I have an ASP.NET 4.0 Silverlight app, but recently a ton of users are complaining about not being able to use the site on mobile devices and Linux distro's. The app is built on MVVM architecture, and thus we are considering changing the UI to alleviate the complaints. We are leaning toward HTML5, but I'm not sure if this is even technically possible with ASP.NET 4.0. I've seen some posts saying that HTML5 only works with javascript code behinds, and that with ASP.NET 4.5 HTML5 support will be added. Am I understanding this correctly? Maybe it would make more sense to just go with an ASPX UI, what are the advantages of HTML5 over .ASPX? Any help is appreciated.
HTML5 is a set of client-side technologies.
ASP.Net is a server-side technology.
They have nothing to do with each-other.
However, it will be easier in ASP.Net MVC.
You would replace what is currently in the Silverlight plugin that runs in the users browser with some html and javascript instead.
It is not technically possible with ASP.NET 4.0. ASP.NET certainly needs the upgrade in order to handle any HTML5-producing code behind or 'plug-ins.' I second the notion of ASP.NET MVC. Also it seems you are comparing a car to gasoline when you ask the advantages of HTML5 over ASPX.
HTML5 works in conjunction with Javascript on the client side. You can still use ASP.NET to process data and deliver content server side. Here are some quick links.
http://visualstudiomagazine.com/articles/2011/09/01/pfcov_html5.aspx
http://mvchtml5.codeplex.com/ (I know it's mvc, but it might be helpful regardless.)
I'm really surprised where somebody telling that all the C# code of the ViewModel and xaml code behind replace with Javascript . Is is possible ? Where in MVVM architecture code are huge and all are responsible for higher task(like communicate with service layer or database).
Is it possible to convert all C# code in JavaScript.
Even I have seen if a JavaScript function take over 25 lines than it becomes some clumsy fro developer to understand . Simple or small functionality can easy develop with javaScript .
C# is very standard and object oriented language ,to develop LOB it has great role but Javascript is not too much .
I'm think Using asp.net mvc is nice to use HTML5 , see we just need to change UI page look using HTML5 but rest of application functionality should remain Same .