Click here to Skip to main content
15,896,513 members
Articles / Web Development / ASP.NET

jQuery Templates/View Engines in ASP.NET MVC

Rate me:
Please Sign up or sign in to vote.
4.88/5 (61 votes)
25 Apr 2012CPOL22 min read 216.2K   4.1K   179  
This article explains how client-side view engines can be used in ASP.NET MVC.
This article introduces a different concept of the view engine - a client-side view engine that renders a view in a client browser. In this concept, the model and the controller are still on the server-side. However, instead of the HTML, JSON is generated as an output from the server-side, it is accepted on the client-side, and HTML is generated using the JavaScript templating engine.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>Load Form with JSON data</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" type="text/css" href="/Content/style.css" />
	<script src="/scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
	<script src="/scripts/jquery.loadJSON.js")" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        $(document).ready(function () {
            var id = window.location.href.match("(ID=|id=|/)[0-9]+")[0].match("[0-9]+");
            $('form').loadJSON('/Company/Data/' + id);
        });
    </script>
</head>

<body>
<div id="page-wrap">
    <div id="contact-area">	
        <form name="form_simple" id="form-simple" action="details.html" method="get">
            <input type="hidden" id="ID" name="ID" />
			<label for="Name">Name</label>
			<input name="Name" id="Name" type="text" />
			<label for="Address">Address</label>
			<textarea name="Address" id="Address" rows="5" cols="20"></textarea>
			<label for="Country">Country</label>
			<select name="Country" multiple="multiple">
                <option value="">-</option>
				<option value="UK">United Kingdom</option>
                <option value="SRB">Serbia</option>
				<option value="USA">United States of America</option>
				<option value="FRA">France</option>  
			</select>
            <br /><br />
			<label for="IsFeatured">Is Featured</label>
			<input name="IsFeatured" id="IsFeatured" type="checkbox" value="true"/>
            <br /><br />
			<label for="Town">Town</label>
			<select name="Town" id="Town">
                <option value="" selected="selected">-</option>
				<option value="London">London City</option>
				<option value="Liverpool">Liverpool City</option>
				<option value="Lothian">Lothian City</option>
				<option value="Newcastle">Newcastle City</option>
                <option value="Buckinghamshire">Buckinghamshire City</option>
                <option value="Essex">Essex City</option>  
			</select>
            <br /><br />
			<label for="Contact">Contact</label>
				<input name="Contact" type="radio" value="Email"/> Email
				<input name="Contact" type="radio" value="Phone" /> Phone
				<input name="Contact" type="radio" value="Post" /> Post
            <input type="submit" value="Details" class="submit-button" />
	    </form>
    </div>
</div>
</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Program Manager Microsoft
Serbia Serbia
Graduated from Faculty of Electrical Engineering, Department of Computer Techniques and Informatics, University of Belgrade, Serbia.
Currently working in Microsoft as Program Manager on SQL Server product.
Member of JQuery community - created few popular plugins (four popular JQuery DataTables add-ins and loadJSON template engine).
Interests: Web and databases, Software engineering process(estimation and standardization), mobile and business intelligence platforms.

Comments and Discussions