Rss Feed Like Us on facebook Google Plus

February 17, 2012

HTML5 for Beginners

Basic Tags

Tags are elements of the HTML language. Almost every kind of tag has an opening symbol and a closing symbol. For example, the <HEAD> tag identifies the beginning of heading information. It also has a closing tag </HEAD>.

<HTML></HTML>

This element tells browsers that the file is a HTML document. Each HTML document starts with the tag <HTML>. This tag should be first thing in the document. It has an associate closing tag </HTML> which must be the last tag in the file.

<HEAD></HEAD>

The head contains important information about the document.

<TITLE></TITLE>

The title tag is an important tag. It is used to display a title on the top of your browser window. Both the opening and the closing tags go between the head tags.
The following example shows how to use the tags:
     <html>
     <head>
     <title>John's Homepage</title>
     </head>
     <body>
     </body>
     </html>

<META>

Another tag that can be added in the head is a <META> tag. It is used to help search engines index a page. There are several different meta names.
The author meta:
     <META NAME="author" CONTENT="Nongjian Zhou">
The description meta:
<META NAME="description" 
        CONTENT="A very easy tutorial for HTML beginners">
The keyword meta. Note that always seperate Keywords with a comma:
<META NAME="keyword"
        CONTENT="html,tutorial,beginner,web design">
The following example shows how these tags are coded:
<head>
<title>HTML For Beginners</title>
<meta name="Author" 
      content="Nongjian Zhou">
<meta name="Description" 
      content="A very easy tutorial for HTML beginners">
<meta name="Keywords"
      content="html,tutorial,beginner,web design">
</head>

<BODY></BODY>

The Body Tag is used to identify the start of the main portion of your webpage. Between <BODY> </BODY> tags you will place all images, links, text, paragraphs, and forms. We will explain each tag that is used within the body of the HTML file.

Character, Paragraph and Position

<H#></H#>

There are six levels of headings, numbered 1 through 6. These tags are used for the characters in the outlines. The biggest heading is <H1> and smallest one is <H6>:
     <H1>Biggest text</H1>
     ......

     <H6>smallest text</H6>

<P></P>

Paragraph tags (<P> opening tag and </P> closing tag) allow you to place a paragraph. For example:
            <p>Basic Information</p>
The </P> closing tag may be omitted.

Align

The defaulted position is left justification. You can also use "ALIGN" for justification: 
     <p ALIGN="center"> Paragraph will be centered</p>  
     <p ALIGN="left"> Paragraph will be left justified</p>
     <p ALIGN="right">Paragraph will be right justified</p> 

<CENTER></CENTER>

This kind of tags have capability of allowing you to center the text on the homepage.
     <center><p> Paragraph will be centered</p></center>

<BR>

This tag break whatever to be on the next line. The following is an example:
     <p>Welcome To<br> My Homepage!</p>

<HR>

This tag adds a horizontal line or divider to your web site. An <HR> tag makes the following divider:
The <hr> tag can be set as:
<hr width="450" align="right" size="5">

You can add spaces in your text by using 

<BLOCKQUOTE></BLOCKQUOTE>

You can use this tag to format or remove a text by movinging both the left and right sides of the paragraph.
     <BLOCKQUOTE>    
     <H1>Welcome To John's Homepage!</H1>
     <p>Content</p>
     <p>Basic Information</p>
     </BLOCKQUOTE>

<PRE></PRE>

Preformatted the text of the paragraph to exactly display what you typed in the Web browser. For example:

     <pre>
     Item     Price     quantity
    -----------------------------
      A       34.99        23
      B       25.95        13
    -----------------------------
     </pre>

Comments

The comment tag looks like this:
     <!-- Comments -->
Nothing inside the comment tags will show up when your page is viewed.

Character Style

Character styles include physical and logical character styles, and Face, Size, and Color. The following is character style table.
TypeChoicefunction
Physical styles<B>Make text bold.
<I>Make text italic.
<U>Make text underline.
<Strike>Make text strikethrough.
<Sup>Make text superscript.
<Sub>Make text subscript.
TeletypeMake text teletype.
Logical styles<Strong>Indicate the text is very important.
<Em>Indicate the text is important.
<Cite>Indicate that the text is from a book or other document.
<Address>Indicate that the text is an address.
<Dfn>Indicate that the text is a definition.
<Samp>Indicate that the text is a sequence of literal characters.
KeyboardIndicate that the text is keyboard input.
<Var>Indicate that the text is a variable.
<Code>Indicate that the text is code.

FontChoiceFunction
FaceDefaultMake text display in the default font (Times New Roman) of the Web browser.
FamilyType a list of fonts separated by commas (for example, Helvetica, Arial, Courier). The text will display in the first listed font found on the browser's system.
(Font name)Make the text display in the font specified. (If the font is not available on the browser's system, another font will be substituted.)
Size1 through 7 (3 is the default)Format text with 7 sizes where 7 is the largest size and 1 is the smallest.
IncreaseFormat text with the largest size (same as 7).
DecreaseFormat text with the smallest size (same as 1).
Color"#xxxxxx" or: White, Red, Blue and OthersMake the text a different color.
The tags below have the effect shown on the text in between.
     <U>underlined text</U>
     <B>bold text</B>
     <I>Italicized text</I>
     <BIG><big>Big text</big></BIG>
     <SMALL>small text</SMALL>
     <TT>Monospaced typewriter text</TT>
     <BLINK><blink>blink</blink></BLINK> 
      (Note: This only works on Netscape)
     <SUB>This <sub>makes a subscript.</sub></SUB>
     <SUP>This<sup> makes a superscript.</sup></SUP>
     <STRIKE>strikeout</STRKE>
     <FONT FACE="Arial">This is a test</FONT>
     <FONT COLOR="#00FF00">Text is in the color of Green</FONT>
     <FONT SIZE="+2">This is a test</FONT>

<BASEFONT>

You may use this tag to set default font face, size or color for your page and save your time of coding. For example:
     <basefont face="Arial" size="7" color="red">

Lists

There are three kinds of lists in HTML:
     Unordered lists <UL></UL>
     Ordered lists <OL></OL>     
     Definition lists <DL></DL>
Unordered Lists
This list starts with an opening list <UL> tag and ends the list with a closing list </UL> tag. Between the <UL> and </UL>, you enter the <LI> (list item) tag followed by the individual item; no closing </LI> tag is needed. For example:
     <UL>
     <LI> Name
     <LI> Phone
     <LI> ID
     </UL>
In the web browser the above code would appear three elements as:
    • Name
    • Phone
    • ID
Ordered Lists
An orderered list is similar to an unordered list, except it uses <OL> instead of <UL>:
     <OL>
     <LI>College
     <LI>Hight School
     <LI>Elemantory School
     </OL>
The output is:
    1. College
    2. Hight School
    3. Elemantory School
Definition Lists
A definition list starts with <DL> and ends with </DL>. This list consists of alternating a definition term and a definition definition. The definition term is enclosed in <DT> </DT> and should precede the definition definition. The definition definition is enclosed in <DD> </DD>. So, a whole definition list looks like:
 
     <DL>
     <DT> term </DT>
     <DD> definition </DD>
      ...
     <DT> term </DT>
     <DD> definition </DD>
     </DL>

Links

Links allow you to navigation from one page to another on the internet or in your local machine. Before you add a link to your page you need a URL of another web site or a path of your local file that you want to link to. The link tag also provides the capability to provide a way for linking an e-mail address. To link to another file in your current dictionary, use <A HREF="name.html"> anchor text </A>. For example:
     <A HREF="bscInfo.html">Basic Information</A>
If you want to link to a file that in another dictionary, you can write the code like this:
     <A HREF="path/name.html">Text</A>
You can create links from your webpage to other webpages on internet:
<A HREF="http://internetcollege.virtualave.net/">Internet College</A>
If you want link to the an email address and when you click it, then start the mail program, you can write the a link like this:
     <A HREF="mailto:internet101@go.com">Email us</A>
If a file has a large size, you may want to create links to different parts of the page. To do that, first you must leave a pointer to the place in the file you want to link to. The pointer looks like <A NAME="xyz">. Then use <A HREF="#xyz"> tags. For example, you want to have a link from the section D to the section "My current project" of your page. Right before "My current project" you need to type <A NAME="M">. At the section D of your page you add the following link: <A HREF="#M">. The # symbol tells your browser to look for the link within the same document instead of looking for another file. You can use any number or letter to replace "M":
     <BODY>
     <A NAME="M"></A>My current projects
     ......
     <A HREF="#M"></A>Click here to see my projects</A>
     </BODY>
You can link to any place in other documents by the same way:
     <A HREF="people.html#F3">Faculty Infomation</A>
You also can link a part of another page on the Internet if you can put a pointer <A NAME=""> in it:
     <A HREF="http://server/path/file#F3">

Image

Most Web browsers can display images that are in GIF, or JPEG format. To include an image, enter:
     <IMG SRC="ImageName">
For example: <IMG SRC="monky.gif"> The <IMG> tag is used to define an image. This tag does not have a closing tag. The IMG part tells the browser to add an image, The SRC tells your browser where to find the image. You should include two other attributes on <IMG> tags to tell your browser the size of the images. The HEIGHT and WIDTH attributes let your browser set aside the appropriate space (in pixels) for the images. For example:
     <IMG SRC="monky.gif" HEIGHT=80 WIDTH=100>
You can put an image in the left or right of a page by using  ALIGN.. For example:
<IMG SRC="ImageName" ALIGN="right">
By default the bottom of an image is aligned with the following text. You can align images to the top, bottom or middle of a paragraph by using one of three things: TOP, MIDDLE, BOTTOM, For example:
     <IMG SRC="monky.gif" ALIGN="top">
Note: You must use "align", not "valign" to set for TOP, MIDDLE, BOTTOM. It's different from the table alignment. We can use "vspace" and "hspace" to adjust space around the picture:
    <IMG SRC="monky.gif" vspace="50" hspace="80">
The ALT attribute is one of IMG attributes. You can use the ALT attribute to specify text to be displayed instead of an image. For example:
     <IMG SRC="monky.gif" ALT="[monky]">
In this example, if someone cannot see the image, at least they will be able to read the name of the image and know that it would be a monky because the words "[monky]" is shown in the place.
An image can be used as hyperlinks just like plain text. The following is the HTML code:
     <A HREF="animal.html"><IMG SRC="monky.gif"></A>
The blue border that surrounds the image indicates that it's a clickable hyperlink. If you do not want to display this border, you can add the BORDER attribute and setting it to zero:
     <A HREF="animal.html"><IMG SRC="monky.gif" BORDER=0></A>
You can load an image from another webpage to your page. To display a image on some one else's page, you need to find the URL:
     <IMG SRC="http://www.abcd.com/image2.gif">
You also can use an image as a background. The tag to include a background image is included in the <BODY> statement as an attribute:
     <BODY BACKGROUND="ImageName">
A large inline image would slow down the loading of the main document. To avoid it, you may have an image open as an external image. To include a reference to an external image, enter:
     <A HREF="ImageName">link anchor</A>
You can also use a smaller image as a link to a larger image. Enter:
     <A HREF="LargerImageName"><IMG SRC="SmallImageName"></A>

Color

You may want to have a specific color for the background, text, links, visited links, and active links. In HTML, Colors are coded as a 6 digit hex RGB (red, green, blue) number. A hexadecimal value in the range 00-FF. For example, 000000 is black (no color at all), FFFFFF is white (fully saturated with all three colors). FF0000 is bright red, 0000FF is bright blue, and 00FF00 is pastel green. You must have the "#" sign before the actual code. You can use the attributes of the <BODY> tag to change the color of text, links, vlinks (visited links), and alinks (active links). For example:
<BODY bgcolor="#FFFFFF" text="#000000" 
      link="#0000FF" vlink="#800000" alink="#808000">
You can also use the name of the color instead of the corresponding RGB value to indicate some basic colors. For example, "black", "red", "blue", and "green" are all valid for use in place of RGB values. Coloring specific text is done very much like changing the font size. The tag is like:
     <FONT color="code"> text </FONT>
This tag can be combined with the font size. For example:
     <FONT color="#00FF00" size="+3"> text </FONT>

Table

The format of table is:
     <TABLE>
     <TR> <TD> Table Entry </TD> ... <TD> Table Entry </TD> 
     </TR>
     ...
     <TR> <TD> Table Entry </TD> ... <TD> Table Entry </TD> 
     </TR>
     </TABLE>
The whole table is opened and closed with <TABLE> </TABLE>. Each row is encapsulated in <TR> </TR>. Within the row are cells, enclosed in <TD> </TD>. There can be as many rows and columns as you want and as will fit on the screen. The browser will autoformat the rows, vertically centering cell contents if necessary. If you want a cell to span more than one column, enclose it in <TD COLSPAN=X> </TD>, where X indicate the number of columns to span. Similarly, <TD ROWSPAN=X> </TD> will cause the cell to span X rows. A border can be placed around all the cells by using <TABLE BORDER=X> </TABLE>, where X is the number of pixels thick the border should be. Let's see an example:
   <CENTER><TABLE BORDER=1 WIDTH="62%" HEIGHT=90>
   <TR>
      <TD WIDTH=82><CENTER> Name</CENTER></TD>
      <TD WIDTH=111><CENTER>Phone</CENTER></TD>
      <TD WIDTH=91><CENTER>ID</CENTER></TD>
   </TR>
   <TR>
      <TD WIDTH=82><CENTER>John Lee</CENTER></TD>
      <TD WIDTH=111><CENTER>456-968</CENTER></TD>
      <TD WIDTH=91><CENTER>276580</CENTER></TD>
   </TR>
   <TR>
      <TD WIDTH=82><CENTER>Cherry Heitz</CENTER></TD>
      <TD WIDTH=111><CENTER>789-326</CENTER></TD>
      <TD WIDTH=91> <CENTER>908743</CENTER></TD>
   </TR>
   </TABLE></CENTER>
Name
Phone
ID
John Lee
456-968
276580
Cherry Heitz
789-326
908743
The value of width and height can be "xx%" or XX. For example: WIDTH="80%" or WIDTH=450. "xx%" allow the table size changing while the window size is changing. The value of Border can be zero. In this case, the table will have no border. You can make a table looking like this:




The following is the code of this table.
     <TABLE BORDER=10 CELLSPACING=10 CELLPADDING=2>
     <TR><TD></TD><TD></TD></TR>
     <TR><TD></TD><TD></TD></TR>
     </TABLE>
The CELLSPACING attribute refers to the space between cells and should be in pixels. The CELLPADDING attribute refers to the spacing within the cell in pixels (the space between the cell walls and the contents of the cell).
Element
Description
<TABLE>
</TABLE>
defines a table in HTML. If the BORDER attribute is present, your browser displays the table with a border.
<CAPTION>
</CAPTION>
defines the caption for the title of the table. The default position of the title is centered at the top of the table. The attribute ALIGN=BOTTOM can be used to position the caption below the table.
NOTE: Any kind of markup tag can be used in the caption.
<TR> </TR>
specifies a table row within a table. You may define default attributes for the entire row: ALIGN (LEFT, CENTER, RIGHT) and/or VALIGN (TOP, MIDDLE, BOTTOM). See Table Attributes at the end of this table for more information.
<TH> </TH>
defines a table header cell. By default the text in this cell is bold and centered. Table header cells may contain other attributes to determine the characteristics of the cell and/or its contents. See Table Attributes at the end of this table for more information.
<TD> </TD>
defines a table data cell. By default the text in this cell is aligned left and centered vertically. Table data cells may contain other attributes to determine the characteristics of the cell and/or its contents. See Table Attributes at the end of this table for more information.
AttributeDescription
ALIGN (LEFT, CENTER, RIGHT)Horizontal alignment of a cell.
VALIGN (TOP, MIDDLE, BOTTOM)Vertical alignment of a cell.
COLSPAN=nThe number (n) of columns a cell spans.
ROWSPAN=nThe number (n) of rows a cell spans.
NOWRAPTurn off word wrapping within a cell.

Form

Forms allow the user to enter information. For example, you can use forms to collect user's names and email addresses. Forms begin with the tag <FORM> and end with 

</FORM>....... </FORM>

Two attributes you should type for your form are the Form Action and Method.:
     <FORM ACTION="http://www.abc.com/cgi-bin/login.pl" METHOD="post">

Input

You can use "input" for single line information:

     <INPUT TYPE="input" NAME=name SIZE=##>
For example:
     <INPUT TYPE="input" NAME="email" SIZE=26>Your Email Address
     <INPUT TYPE="input" NAME="name" SIZE=26>Your Name
     <INPUT TYPE="input" NAME="subject" SIZE=26>Subject
Here is what the result shows:
     <input size="26" name="email" /> Your Email Address
     <input size="26" name="firstname" /> Your Name
     <input size="26" name="subject" /> Subject
The value of size is in characters, so "SIZE=26" means the width of the input box is 26 characters. 

Text Area

Text Area can be as big as you'd like. Text Area begins with <TEXTAREA NAME=name ROWS=## COLS=##>and end with </TEXTAREA>. For example:
     <TEXTAREA Rows=2 Cols=25 NAME="comments"></TEXTAREA>
The result is:
     
<textarea cols="25" name="comments" />

Radio Button

You can use radio buttons to ask a question with one answer. For example, if you wanted to ask "Which picture do you like?" and you wanted to have the choices "monky", "flower", "girl", "building", you would type:
     <INPUT TYPE="radio" checked NAME="picture" VALUE="monky">Monky<P>
     <INPUT TYPE="radio" NAME="picture" VALUE="flower">Flower<P>
     <INPUT TYPE="radio" NAME="picture" VALUE="girl">Girl<P>
     <INPUT TYPE="radio" NAME="picture" VALUE="building">Building<P>
The Result is:
     <input checked="true" type="radio" name="picture" /> Monky
     <input type="radio" name="picture" /> Flower
     <input type="radio" name="picture" /> Girl
     <input type="radio" name="picture" /> Building

Check Box

Checkboxes let the user check things from a list. The form is:
     <INPUT TYPE="checkbox" NAME="name" VALUE="text">
Notice that the difference between check boxes and radio buttons is that any number of check boxes can be checked at one time while only one radio button can be checked at a time. For example, if you wanted to ask "Which picture do you like?" and you allow any number of check boxes can be checked at one time, you would type:
     <INPUT TYPE="checkbox" NAME="picture" VALUE="monky">Monky<P>
     <INPUT TYPE="checkbox" NAME="picture" VALUE="flower">Flower<P>
     <INPUT TYPE="checkbox" NAME="picture" VALUE="girl">Girl<P>
     <INPUT TYPE="checkbox" NAME="picture" VALUE="building">Building<P>
The result is:
     Which picture do you like?
     <input type="checkbox" name="picture" /> Monky
     <input type="checkbox" name="picture" /> Flower
     <input type="checkbox" name="picture" /> Girl
     <input type="checkbox" name="picture" /> Building

Submit and Reset

Other button types include submit and reset. "submit" is the button the user presses to send in the form. "reset" clears the entire form so the user can start over. For example:
     <INPUT TYPE="submit" NAME="submit" VALUE="Send">
     <INPUT TYPE="reset" NAME="reset" VALUE="Clear">
The result is:
     <input type="submit" name="submit" /><input type="reset" name="reset" />

Password

This type allows users to type in text but instead of displaying the text that they type astericks are displayed instead:
     <INPUT TYPE="password" NAME="pass" SIZE="20">

Pull-Down Menu

You can ask a question with only one answer is by using a pull-down menu. For example:
     How old are you? 
     <SELECT NAME="age">
     <OPTION>1-15
     <OPTION SELECTED >16-21
     <OPTION>22-30
     <OPTION>31-45
     <OPTION>46-65
     <OPTION>66-80
     <OPTION>81-up
     </SELECT>
The result is:
     How old are you? 
     <select size="1" name="age"> <option>1-15</option> 
     <option>16-21</option> <option>22-30</option> 
     <option>31-45</option> <option>46-65</option> <option>66-80</option> 
     <option>81-up</option></select>

Scroll-Down Menu

Ther are two kinds of scroll-down menus. One is that you can only select one item:
     How old are you?
     <SELECT NAME="age" SIZE=5>
     <OPTION VALUE="1-15">1-15
     <OPTION VALUE="16-21">16-21
     <OPTION VALUE="22-30">22-30
     <OPTION VALUE="31-45">31-45
     <OPTION VALUE="46-65">46-65
     <OPTION VALUE="66-80">66-80
     <OPTION VALUE="81-up">81-up
     </SELECT>
The result is:
     How old are you? 
     <select size="5" name="age"> <option value="1-15">1-15</option> 
     <option value="16-21">16-21</option> <option value="22-30">22-30</option> 
     <option value="31-45">31-45</option> <option value="46-65">46-65</option> 
     <option value="66-80">66-80</option> <option value="80-up">80-up</option></select>
The other menu is that you can select one or more items by holding down shift. For example:
     What is your favorite thing?
     (Hold <i>shift</i> to select more that one)
     <SELECT NAME="reading" MULTIPLE size="3">reading
     <OPTION VALUE="sports">sports
     <OPTION VALUE="travelling">travelling
     <OPTION VALUE="music">music
     <OPTION VALUE="cooking">cooking
     <OPTION VALUE="shopping">shopping
     <OPTION VALUE="talking">talking
     </SELECT><P>
The point is "multiple".

Frame

With frames, you can put a number of HTML pages into a single window, each of frame can display a page. frames start and end with the <FRAMESET></FRAMSET> tags. The <FRAMESET> tag can have two modifiers: ROWS and COLS to define how big the frames will be. For example:
<html>
<head><title></title></head>  
<frameset rows="64,*">
<frame name="banner" scrolling="no" noresize 
         target="contents" src="top.htm">  
<frameset cols="150,*">
<frame name="contents" target="main" 
         src="menu.htm">
<frame name="main" src="home.htm">
</frameset>
<noframes>
<body>
<p>This page uses frames, but your browser doesn't 
support them.</p>
</body>
</noframes>
</frameset> 
</html>
Let's explain each element:
rows="64,*" means that the the first frame will take up 64 rows of the window and the second frame will take up the rest. An asterisk means that the row will take up whatever space is left. You can use percentage to replace length. For example: cols="30%,60%"
<frame> defines each individual frame.
name="..." gives the frame a name.
src="..." tells which page will be loaded in the frame.
target="..." allows you to make links appear in specific frames or windows.
scrolling="yes|no|auto" allows you to control the scroll bars on the frame. "yes" forces the frame to always have scroll bars. "no" forces the frame to never have scroll bars. "auto" allows the browser to decide if scroll bars are necessary. The default value is "auto".
noresize allows you to keep the frame from being resizable by the viewer.
</noframes> is used to create a frameless alternate. When the page is viewed by a browser that does not support frames, everything EXCEPT what is between the </noframes> tags is ignored.
There are also some "magic" TARGETs.
"_blank" will always open the link in a new window.
"_top" will open the link in the whole page, instead of in a single frame.
"_self" makes the link open in the frame it's called from. This is useful when the <BASE...> tag is used.
"_parent" opens the link in the immediate frameset parent of the frame the link is called from.
Example:
     <A HREF="ah.html" TARGET="_blank">text</A>
And, TARGET can also be added to the <FORM> tag to make the output from the script got to the specified frame or window.

Read More

“Razor” – a new view engine for ASP.NET MVC


One of the things my team has been working on has been a new view engine option for ASP.NET.

ASP.NET MVC has always supported the concept of “view engines” – which are the pluggable modules that implement different template syntax options.  The “default” view engine for ASP.NET MVC today uses the same .aspx/.ascx/.master file templates as ASP.NET Web Forms.  Other popular ASP.NET MVC view engines used today include Spark and NHaml.

The new view-engine option we’ve been working on is optimized around HTML generation using a code-focused templating approach. The codename for this new view engine is “Razor”, and we’ll be shipping the first public beta of it shortly.

Design Goals


We had several design goals in mind as we prototyped and evaluated “Razor”:
  • Compact, Expressive, and Fluid: Razor minimizes the number of characters and keystrokes required in a file, and enables a fast, fluid coding workflow. Unlike most template syntaxes, you do not need to interrupt your coding to explicitly denote server blocks within your HTML. The parser is smart enough to infer this from your code. This enables a really compact and expressive syntax which is clean, fast and fun to type.
  • Easy to Learn: Razor is easy to learn and enables you to quickly be productive with a minimum of concepts. You use all your existing language and HTML skills.
  • Is not a new language: We consciously chose not to create a new imperative language with Razor. Instead we wanted to enable developers to use their existing C#/VB (or other) language skills with Razor, and deliver a template markup syntax that enables an awesome HTML construction workflow with your language of choice.
  • Works with any Text Editor: Razor doesn’t require a specific tool and enables you to be productive in any plain old text editor (notepad works great).
  • Has great Intellisense: While Razor has been designed to not require a specific tool or code editor, it will have awesome statement completion support within Visual Studio. We’ll be updating Visual Studio 2010 and Visual Web Developer 2010 to have full editor intellisense for it.
  • Unit Testable: The new view engine implementation will support the ability to unit test views (without requiring a controller or web-server, and can be hosted in any unit test project – no special app-domain required).
We’ve spent the last few months building applications with it and doing lots of usability studies of it with a variety of volunteers (including several groups of non-.NET web developers). The feedback so far from people using it has been really great.

Choice and Flexibility

One of the best things about ASP.NET is that most things in it are pluggable. If you find something doesn’t work the way you want it to, you can swap it out for something else.
The next release of ASP.NET MVC will include a new “Add->View” dialog that makes it easy for you to choose the syntax you want to use when you create a new view template file.  It will allow you to easily select any of of the available view engines you have installed on your machine – giving you the choice to use whichever view approach feels most natural to you:
AddView9
Razor will be one of the view engine options we ship built-into ASP.NET MVC.  All view helper methods and programming model features will be available with both Razor and the .ASPX view engine. 
You’ll also be able to mix and match view templates written using multiple view-engines within a single application or site.  For example, you could write some views using .aspx files, some with .cshtml or .vbhtml files (the file-extensions for Razor files – C# and VB respectively), and some with Spark or NHaml.  You can also have a view template using one view-engine use a partial view template written in another.  You’ll have full choice and flexibility.

Hello World Sample with Razor

Razor enables you to start with static HTML (or any textual content) and then make it dynamic by adding server code to it.  One of the core design goals behind Razor is to make this coding process fluid, and to enable you to quickly integrate server code into your HTML markup with a minimum of keystrokes.
To see a quick example of this let’s create a simple “hello world” sample that outputs a message like so:
image
Building it with .ASPX Code Nuggets
If we were to build the above “hello world” sample using ASP.NET’s existing .ASPX markup syntax, we might write it using <%= %> blocks to indicate “code nuggets” within our HTML markup like so:
image
One observation to make about this “hello world” sample is that each code nugget block requires 5 characters (<%= %>) to denote the start and stop of the code sequence.  Some of these characters (in particular the % key – which is center top on most keyboards) aren’t the easiest to touch-type.
Building it with Razor Syntax
You denote the start of a code block with Razor using a @ character.  Unlike <% %> code nuggets, Razor does not require you to explicitly close the code-block:
image
The Razor parser has semantic knowledge of C#/VB code used within code-blocks – which is why we didn’t need to explicitly close the code blocks above.  Razor was able to identify the above statements as self-contained code blocks, and implicitly closed them for us.
Even in this trivial “hello world” example we’ve managed to save ourselves 12 keystrokes over what we had to type before.  The @ character is also easier to reach on the keyboard than the % character which makes it faster and more fluid to type. 

Loops and Nested HTML Sample

Let’s look at another simple scenario where we want to list some products (and the price of each product beside it):
image
Building it with .ASPX Code Nuggets
If we were to implement this using ASP.NET’s existing .ASPX markup syntax, we might write the below code to dynamically generate a <ul> list with <li> items for each product inside it:
image 
Building it with Razor Syntax
Below is how to generate the equivalent output using Razor:
image
Notice above how we started a “foreach” loop using the @ symbol, and then contained a line of HTML content with code blocks within it.  Because the Razor parser understands the C# semantics in our code block, it was able to determine that the <li> content should be contained within the foreach and treated like content that should be looped.  It also recognized that the trailing } terminated the foreach statement.
Razor was also smart enough to identify the @p.Name and @p.Price statements within the <li> element as server code – and execute them each time through the loop. Notice how Razor was smart enough to automatically close the @p.Name and @p.Price code blocks by inferring how the HTML and code is being used together.
The ability to code like this without having to add lots of open/close markers throughout your templates ends up making the whole coding process really fluid and fast.

If-Blocks and Multi-line Statements

Below are a few examples of other common scenarios:
If Statements
Like our foreach example above, you can embed content within if statements (or any other C# or VB language construct), without having to be explicit about the code block’s begin/end.  For example:
image
Multi-line Statements
You can denote multiple lines of code by wrapping it within a @{ code } block like so:
image 
Notice above how variables can span multiple server code blocks – the “message” variable defined within the multi-line @{ } block, for example, is also being used within the @message code block.  This is conceptually the same as the <% %> and <%= %> syntax within .aspx markup files.
Multi-Token Statements
The @( ) syntax enables a code block to have multiple tokens.  For example, we could re-write the above code to concatenate a string and the number together within a @( code ) block:
image 

Integrating Content and Code

The Razor parser has a lot of language smarts built-into it – enabling you to rely on it to do the heavily lifting, as opposed to you having to explicitly do it yourself. 
Does it break with email addresses and other usages of @ in HTML?
Razor’s language parser is clever enough in most cases to infer whether a @ character within a template is being used for code or static content.  For example, below I’m using a @ character as part of an email address:
image
When parsing a file, Razor examines the content on the right-hand side of any @ character and attempts to determine whether it is C# code (if it is a CSHTML file) or VB code (if it is a VBHTML file) or whether it is just static content.  The above code will output the following HTML (where the email address is output as static content and the @DateTime.Now is evaluated as code:
image
In cases where the content is valid as code as well (and you want to treat it as content), you can explicitly escape out @ characters by typing @@.
Identifying Nested Content
When nesting HTML content within an if/else, foreach or other block statement, you should look to wrap the inner content within an HTML or XML element to better identify that it is the beginning of a content block.
For example, below I’ve wrapped a multi-line content block (which includes a code-nugget) with a <span> element:
image
This will render the below content to the client – note that it includes the <span> tag:
image
You can optionally wrap nested content with a <text> block for cases where you have content that you want to render to the client without a wrapping tag:
image
The above code will render the below content to the client – note that it does not include any wrapping tag:
image 
HTML Encoding
By default content emitted using a @ block is automatically HTML encoded to better protect against XSS attack scenarios.

Layout/MasterPage Scenarios – The Basics

It is important to have a consistent look and feel across all of the pages within your web-site/application.  ASP.NET 2.0 introduced the concept of “master pages” which helps enable this when using .aspx based pages or templates.  Razor also supports this concept using “layout pages” – which allow you to define a common site template, and then inherit its look and feel across all the views/pages on your site.
Simple Layout Example
Below is a simple example of a layout page – which we’ll save in a file called “SiteLayout.cshtml”.  It can contain any static HTML content we want to include in it, as well as dynamic server code.  We’ll then add a call to the “RenderBody()” helper method at the location in the template where we want to “fill in” specific body content for a requested URL:
image
We can then create a view template called “Home.cshtml” that contains only the content/code necessary to construct the specific body of a requested page, and which relies on the layout template for its outer content:
image
Notice above how we are explicitly setting the “LayoutPage” property in code within our Home.cshtml file.  This indicates that we want to use the SiteLayout.cshtml template as the layout for this view.  We could alternatively indicate the layout file we want to use within a ASP.NET MVC Controller invoking Home.cshtml as a view template, or by configuring it as the default layout to use for our site (in which case we can specify it in one file in our project and have all view templates pick it up automatically).
When we render Home.cshtml as a view-template, it will combine the content from the layout and sub-page and send the following content to the client:
image

Compact, Clean, Expressive Code

One of the things to notice in the code above is that the syntax for defining layouts and using them from views/pages is clean and minimal.  The code screen-shots above of the SiteLayout.cshtml and Home.cshtml files contain literally all of the content in the two .cshtml files – there is no extra configuration or additional tags, no <%@ Page%> prefix, nor any other markup or properties that need to be set.
We are trying to keep the code you write compact, easy and fluid.  We also want to enable anyone with a text editor to be able to open, edit and easily tweak/customize them.  No code generation or intellisense required.

Layout/MasterPage Scenarios – Adding Section Overrides

Layout pages optionally support the ability to define different “sections” within them that view templates based on the layout can then override and “fill-in” with custom content.  This enables you to easily override/fill-in discontinuous content regions within a layout page, and provides you with a lot of layout flexibility for your site.
For example, we could return to our SiteLayout.cshtml file and define two sections within our layout that the view templates within our site can optionally choose to fill-in.  We’ll name these sections “menu” and “footer” – and indicate that they are optional (and not required) within our site by passing an optional=true parameter to the RenderSection() helper call .
image
Because these two sections are marked as “optional”, I’m not required to define them within my Home.cshtml file.  My site will continue to work fine if they aren’t there. 
Let’s go back into Home.cshtml, though, and define a custom Menu and Footer section for them.  The below screenshot contains all of the content in Home.cshtml – there is nothing else required in the file.  Note: I moved setting the LayoutPage to be a site wide setting – which is why it is no longer there.
image
Our custom “menu” and “footer” section overrides are being defined within named @section { } blocks within the file.  We chose not to require you to wrap the “main/body” content within a section and instead to just keep it inline (which both saves keystrokes and enables you to easily add sections to your layout pages without having to go back through all your existing pages changing their syntax). 
When we render Home.cshtml as a view-template again, it will now combine the content from the layout and sub-page, integrating the two new custom section overrides in it, and send down the following content to the client:
image

Encapsulation and Re-Use with HTML Helpers

We’ve covered how to maintain a consistent site-wide look and feel using layout pages.  Let’s now look at how we can also create re-usable “HTML helpers” that enable us to cleanly encapsulate HTML generation functionality into libraries that we can re-use across our site – or even across multiple different sites.
Code Based HTML Helpers
ASP.NET MVC today has the concept of “HTML Helpers” – which are methods that can be invoked within code-blocks, and which encapsulate generating HTML.  These are implemented using pure code today (typically as extension methods).  All of the existing HTML extension methods built with ASP.NET MVC (both ones we’ve built and ones built by others) will work using the “Razor” view engine (no code changes required):
image
Declarative HTML Helpers
Generating HTML output using a code-only class approach works – but is not ideal.
One of the features we are looking to enable with Razor is an easy way to create re-usable HTML helpers using a more declarative approach.  Our plan is to enable you to define reusable helpers using a @helper { } declarative syntax like below. 
image
You’ll be able to place .cshtml files that contain these helpers into a Views\Helpers directory and then re-use them from any view or page in your site (no extra steps required):
image
Note above how our ProductListing() helper is able to define arguments and parameters.  This enables you to pass any parameters you want to them (and take full advantage of existing languages features like optional parameters, nullable types, generics, etc).  You’ll also get debugging support for them within Visual Studio.
Note: The @helper syntax won’t be in the first beta of Razor – but is something we hope will be enabled with the next drop.  Code-based helpers will work with the first beta.
Passing Inline Templates as Parameters
One other useful (and extremely powerful) feature we are enabling with Razor is the ability to pass “inline template” parameters to helper methods.  These “inline templates” can contain both HTML and code, and can be invoked on-demand by helper methods.
Below is an example of this feature in action using a “Grid” HTML Helper that renders a DataGrid to the client:
image
The Grid.Render() method call above is C#.  We are using the new C# named parameter syntax to pass strongly-typed arguments to the Grid.Render method - which means we get full statement completion/intellisense and compile-time checking for the above syntax.
The “format” parameter we are passing when defining columns is an “inline template” – which contains both custom html and code, and which we can use to customize the format of the data.  What is powerful about this is that the Grid helper can invoke our inline template as a delegate method, and invoke it as needed and as many times as it wants. In the scenario above it will call it each time it renders a row in the grid – and pass in the “item” that our template can use to display the appropriate response.
This capability will enable much richer HTML helper methods to be developed.  You’ll be able to implement them using both a code approach (like the way you build extension methods today) as well as using the declarative @helper {} approach.

Visual Studio Support

As I mentioned earlier, one of our goals with Razor is to minimize typing, and enable it to be easily edited with nothing more than a basic text editor (notepad works great).  We’ve kept the syntax clean, compact and simple to help enable that.
We have also designed Razor so that you get a rich code editing experience within Visual Studio.  We will provide full HTML, JavaScript and C#/VB code intellisense within Razor based files:
image
Notice above how we are providing intellisense for a Product object on the “@p.” code embedded within the <li> element inside a foreach loop.  Also notice how our \Views folder within the Solution Explorer contains both .aspx and .cshtml view templates.  You can use multiple view engines within a single application – making it easy to choose whichever syntax feels best to you.

Summary

We think “Razor” provides a great new view-engine option that is streamlined for code-focused templating.  It a coding workflow that is fast, expressive and fun.  It’s syntax is compact and reduces typing – while at the same time improving the overall readability of your markup and code.  It will be shipping as a built-in view engine with the next release of ASP.NET MVC.  You can also drop standalone .cshtml/.vbhtml files into your application and run them as single-pages – which also enables you to take advantage of it within ASP.NET Web Forms applications as well.
Read More

Facebook Goes Twitter way to verify Popular Account

Facebook will allow a small number of public figures to verify their accounts beginning today, a spokesperson from the company confirms.

Users with verified accounts will appear more often in “People To Subscribe To” recommendations on the site, but unlike on Twitter and Google+, there will be no visual indication that a profile is official. These users will also have the option to display their more well-known pseudonyms, if applicable. For example, Curtis Jackson could choose to go by his stage name 50 Cent across the site, instead of displaying it as an alternate name as he does now.



Facebook says users with a large number of subscribers will see a notification to verify their accounts. Not everyone who allows subscribers will see this option, and for now, users cannot request to be verified.

The feature will start as invite-only, allowing public figures (in the beginning, only users with high subscriber counts will be invited) to change their account to verified status.

Once the account is verified, it will appear more frequently in the “people to subscribe to” list. 

Twitter launched verified accounts back in 2009, and Google+ launched a similar feature shortly after launch. 

However, unlike Twitter’s version of this feature, Facebook won’t display any sort of badge on verified accounts – a somewhat odd decision, since having a way to distinguish the real person from impostors is precisely why this feature is useful to most users.

Instead, verified users will have the option to display a nickname (Facebook normally requires all users to use their real name) instead of a real name, or have their real name places in parentheses. 

How To Verify

"To verify your account, you’ll have to send Facebook an image of a government-issued photo ID, or a combination of two alternate IDs (such as birth certificate and credit card). While this will certainly make some users uneasy, Facebook promises to delete this data after verification."
Read More

February 16, 2012

HTML5 Games vs Flash Games [infographic]

Read More

© 2011-2016 Techimpulsion All Rights Reserved.


The content is copyrighted to Tech Impulsion and may not be reproduced on other websites.