<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-7510043426665993888</id><updated>2026-09-30T13:41:20.513+05:30</updated><category term="MVC"/><category term="asp.net"/><category term=".NET"/><category term="JQuery"/><category term="Razor"/><category term="ASP.NET MVC"/><category term="VWD 2010"/><category term="carousel"/><category term="css"/><category term="diy"/><category term="dot net"/><category term="Captcha"/><category term="Email"/><category term="Entity"/><category term="Entity framework"/><category term="Export to Excel"/><category term="Image upload"/><category term="JQuery ASP.NET MVC"/><category term="ReCaptcha"/><category term="SQL Express"/><category term="ViewModel"/><category term="WYSIWYG"/><category term="ckeditor"/><category term="free image upload"/><category term="modal dialog form"/><category term="modal form"/><category term="simple"/><category term="sqlexpress"/><title type='text'>Amit Raya</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://amitraya.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7510043426665993888/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://amitraya.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Amit Raya</name><uri>http://www.blogger.com/profile/10060067214284586056</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>6</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-7510043426665993888.post-5831705520029802629</id><published>2015-07-21T18:42:00.000+05:30</published><updated>2015-07-21T18:43:39.228+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="carousel"/><category scheme="http://www.blogger.com/atom/ns#" term="css"/><category scheme="http://www.blogger.com/atom/ns#" term="diy"/><category scheme="http://www.blogger.com/atom/ns#" term="JQuery"/><title type='text'>Easy DIY Carousel using Jquery (Updated to include two carousel and slider button)</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
This is update to my last blog &lt;a href=&quot;http://amitraya.blogspot.com/2015/07/easy-diy-carousel-using-jquery.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: #2288bb;&quot;&gt;Easy DIY Carousel using Jquery&lt;/span&gt;&lt;/a&gt;&amp;nbsp;and I have updated some code from the initial works for making the code reusable in moveleft() and moveright() function, also I have added one more carousel to show how we can have two carousel showing independent images but when on is clicked the other one also moves. I have also introduced a slider below using which you can go to specific slide without having to look at other slides. I have also moved all script from the html to another .js file.&lt;br /&gt;
&lt;br /&gt;
So let&#39;s start, first off let&#39;s have the same code as given in &lt;a href=&quot;http://amitraya.blogspot.com/2015/07/easy-diy-carousel-using-jquery.html&quot; target=&quot;_blank&quot;&gt;&lt;span style=&quot;color: #2288bb;&quot;&gt;Easy DIY Carousel using Jquery&lt;/span&gt;&lt;/a&gt;&amp;nbsp; blog. Now create another div and call it carousel1 and rest of the content and div inside the carousel remains the same as the first one. The only different in the inside of carousel and carousel1 is the fact that carousel contains counter whereas carousel1 doesn&#39;t because we are using the same counter for both the carousel. Also added is another div called navig which will give us the slider button.&lt;br /&gt;
&lt;br /&gt;
After adding the new carousel and the slider&amp;nbsp;the html code looks like this:&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;&quot;&gt;&amp;lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot;
&quot;&lt;a href=&quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt;http://www.w3.org/TR/html4/strict.dtd&lt;/a&gt;&quot;&amp;gt;
&amp;lt;html xmlns=&quot;&lt;a href=&quot;http://www.w3.org/1999/xhtml&quot;&gt;http://www.w3.org/1999/xhtml&lt;/a&gt;&quot; lang=&quot;en&quot;&amp;gt;
&amp;nbsp;&amp;lt;head&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;title&amp;gt;Carousel&amp;lt;/title&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;meta name=&quot;author&quot; content=&quot;amit.raya&quot; /&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;!-- Date: 2015-07-12 --&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;script src=&quot;jquery-2.1.4.min.js&quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;script src=&quot;jquery-ui.js&quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;!--Added new javascript file and removed all jquery code from the html--&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;script src=&quot;myjs.js&quot;&amp;gt;&amp;lt;/script&amp;gt; 
&amp;nbsp;&amp;nbsp;&amp;lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;mystyle.css&quot;/&amp;gt;
&amp;nbsp;&amp;lt;/head&amp;gt;
&amp;nbsp;&amp;lt;body&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;!--The first carousel--&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;carousel&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;main one&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;inside&quot;&amp;gt;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;main two&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;inside&quot;&amp;gt;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;main three&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;inside&quot;&amp;gt;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;main four&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;inside&quot;&amp;gt;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;pointerleft&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;img src=&quot;Images/llt.png&quot; /&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;pointerright&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;img src=&quot;Images/right.png&quot; /&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;counter&quot; data-count=&quot;1&quot;&amp;gt;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;!--Newly added carousel--&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;carousel1&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;main one&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;inside&quot;&amp;gt;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;main two&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;inside&quot;&amp;gt;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;main three&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;inside&quot;&amp;gt;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;main four&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;inside&quot;&amp;gt;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;pointerleft&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;img src=&quot;Images/llt.png&quot; /&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;pointerright&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;img src=&quot;Images/right.png&quot; /&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;!--HTML for the slider panel--&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;ul class=&quot;navig&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;li&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;a class=&quot;d1&quot;&amp;gt;&amp;lt;/a&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/li&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;li&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;a class=&quot;d2&quot;&amp;gt;&amp;lt;/a&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/li&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;li&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;a class=&quot;d3&quot;&amp;gt;&amp;lt;/a&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/li&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;li&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;a class=&quot;d4&quot;&amp;gt;&amp;lt;/a&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/li&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;!--Reserved if there are more than 4 slides--&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;!-- &amp;lt;li&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;a class=&quot;d5&quot;&amp;gt;&amp;lt;/a&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/li&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;li&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;a class=&quot;d6&quot;&amp;gt;&amp;lt;/a&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/li&amp;gt; --&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;lt;/ul&amp;gt;
&amp;nbsp;&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/pre&gt;
&lt;br /&gt;
Now that we have completed the HTML let&#39;s complete the css for the&amp;nbsp; for the slider and new carousel. First I will put only the part of code which is for the carousel1 and slider then I will paste the whole css. This will help you understand what has been added since the last blog.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;&quot;&gt;.carousel{
&amp;nbsp;position:relative;
&amp;nbsp;width:450px;
&amp;nbsp;min-height: 550px;
&amp;nbsp;overflow:hidden;
&amp;nbsp;float:left;
&amp;nbsp;left:150px; /*changed from the last blog to have space enough for two carousel in the page*/
}
.carousel1{
&amp;nbsp;position:relative;
&amp;nbsp;width:450px;
&amp;nbsp;min-height: 550px;
&amp;nbsp;overflow:hidden;
&amp;nbsp;float:left;
&amp;nbsp;left:150px;
}
.navig{
&amp;nbsp;position:absolute;
&amp;nbsp;top:600px; /*adjust these values to suit your need*/
&amp;nbsp;left:475px; /*adjust these values to suit your need*/
}
.navig li{
&amp;nbsp;list-style: none;
&amp;nbsp;float:left;
&amp;nbsp;margin-left:10px;
}
.navig li a{
&amp;nbsp;padding:10px 5px;
&amp;nbsp;text-decoration: none;
&amp;nbsp;position: relative;
&amp;nbsp;display: inline-block;
&amp;nbsp;cursor: pointer;
&amp;nbsp;-webkit-perspective: 500px;
&amp;nbsp;-moz-perspective: 500px;
&amp;nbsp;-ms-perspective: 500px;
&amp;nbsp;-o-perspective: 500px;
&amp;nbsp;perspective: 500px;
&amp;nbsp;margin: 0 6px;
&amp;nbsp;padding: 9px;
&amp;nbsp;-webkit-border-radius: 50%;
&amp;nbsp;-moz-border-radius: 50%;
&amp;nbsp;border-radius: 50%;
&amp;nbsp;background: #000;
&amp;nbsp;background-color: rgb(51, 153, 255,0.6);
}&lt;/pre&gt;
Now the full CSS will look like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;&quot;&gt;.carousel{
&amp;nbsp;position:relative;
&amp;nbsp;width:450px;
&amp;nbsp;min-height: 550px;
&amp;nbsp;overflow:hidden;
&amp;nbsp;float:left;
&amp;nbsp;left:150px; /*changed from the last blog to have space enough for two carousel in the page*/
}
/*new carousel*/
.carousel1{
&amp;nbsp;position:relative;
&amp;nbsp;width:450px;
&amp;nbsp;min-height: 550px;
&amp;nbsp;overflow:hidden;
&amp;nbsp;float:left;
&amp;nbsp;left:150px;
}
.main{
&amp;nbsp;position:absolute;
&amp;nbsp;margin-left: -450px;;
}
.inside{
&amp;nbsp;min-width: 400px;
&amp;nbsp;min-height: 500px;
&amp;nbsp;background-color:yellow;
&amp;nbsp;margin:20px;
}
.one{
&amp;nbsp;background-color:green;
}
.two{
&amp;nbsp;background-color:red;
}
.three{
&amp;nbsp;background-color:grey;
}
.four{
&amp;nbsp;background-color:blue;
}
.pushright{
&amp;nbsp;right:300px;
}
.pointerright, .pointerleft{
&amp;nbsp;position:absolute;
&amp;nbsp;top:230px;
}
.pointerleft{
&amp;nbsp;left:-43px;
}
.pointerright{
&amp;nbsp;right:-43px;
}
.navig{
&amp;nbsp;position:absolute;
&amp;nbsp;top:600px; /*adjust these values to suit your needs*/
&amp;nbsp;left:475px; /*adjust these values to suit your needs*/
}
.navig li{
&amp;nbsp;list-style: none;
&amp;nbsp;float:left;
&amp;nbsp;margin-left:10px;
}
.navig li a{
&amp;nbsp;padding:10px 5px;
&amp;nbsp;text-decoration: none;
&amp;nbsp;position: relative;
&amp;nbsp;display: inline-block;
&amp;nbsp;cursor: pointer;
&amp;nbsp;-webkit-perspective: 500px;
&amp;nbsp;-moz-perspective: 500px;
&amp;nbsp;-ms-perspective: 500px;
&amp;nbsp;-o-perspective: 500px;
&amp;nbsp;perspective: 500px;
&amp;nbsp;margin: 0 6px;
&amp;nbsp;padding: 9px;
&amp;nbsp;-webkit-border-radius: 50%;
&amp;nbsp;-moz-border-radius: 50%;
&amp;nbsp;border-radius: 50%;
&amp;nbsp;background: #000;
&amp;nbsp;background-color: rgb(51, 153, 255,0.6);
}&lt;/pre&gt;
Now once that is out of our way let&#39;s look at the jquery that we need.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;&quot;&gt;$(document).ready(function(){
&amp;nbsp;&amp;nbsp;$( &quot;.one&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;slow&quot;); // initially start with 1
&amp;nbsp;&amp;nbsp;$(&quot;.pointerright&quot;).click(function(){ //if the move right pointer is clicked
&amp;nbsp;&amp;nbsp;&amp;nbsp;moveright(); //point to the moveright function
&amp;nbsp;&amp;nbsp;});
&amp;nbsp;&amp;nbsp;$(&quot;.pointerleft&quot;).click(function(){//if the move left pointer is clicked
&amp;nbsp;&amp;nbsp;&amp;nbsp;moveleft(); //point to the moveleft function
&amp;nbsp;&amp;nbsp;});
&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;$(document).keydown(function(e){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if (e.keyCode == 39 || e.keyCode == 40) // Right down arrow 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;moveright(); //point to the moveright function
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;}else if (e.keyCode == 37 || e.keyCode == 38) // left up arrow
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;moveleft(); //point to the moveleft function
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp; &amp;nbsp;});
&amp;nbsp;&amp;nbsp; &amp;nbsp;$(&quot;.d1&quot;).click(function(){
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;var counter = $(&quot;.counter&quot;).attr(&quot;data-count&quot;); //get the counter value
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;if(counter==2){
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;$( &quot;.one&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;slow&quot;); //move the first slide to visible window
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.two&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;slow&quot;); //move the second slide to initial placeholder
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;if(counter==3){
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;$( &quot;.one&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;slow&quot;); //move the first slide to visible window
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.two&quot; ).animate({ &quot;left&quot;: &quot;-=900px&quot; },&quot;slow&quot;); //move the second slide to initial placeholder
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.three&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;slow&quot;); //move the third slide to initial placeholder
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;if(counter==4){
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;$( &quot;.one&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;slow&quot;); //move the first slide to visible window
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.two&quot; ).animate({ &quot;left&quot;: &quot;-=900px&quot; },&quot;slow&quot;); //move the second slide to initial placeholder
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.three&quot; ).animate({ &quot;left&quot;: &quot;-=900px&quot; },&quot;slow&quot;); //move the second slide to initial placeholder
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.four&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;slow&quot;); //move the fourth slide to initial placeholder
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;$(&quot;.counter&quot;).attr(&quot;data-count&quot;,&quot;1&quot;); //set the counter to 1
&amp;nbsp;&amp;nbsp; &amp;nbsp;});
&amp;nbsp;&amp;nbsp; &amp;nbsp;$(&quot;.d2&quot;).click(function(){
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;var counter = $(&quot;.counter&quot;).attr(&quot;data-count&quot;); //get the counter value
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;if(counter==1){
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;$( &quot;.one&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;slow&quot;); //move the first slide to final placeholder
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.two&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;slow&quot;); //move the second slide to visible window
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;if(counter==3){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.two&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;slow&quot;); //move the second slide to visible window
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.three&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;slow&quot;); //move the third slide to initial placeholder
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;if(counter==4){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.two&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;slow&quot;); //move the second slide to visible window
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.three&quot; ).animate({ &quot;left&quot;: &quot;-=900px&quot; },&quot;slow&quot;); //move the third slide to initial placeholder
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.four&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;slow&quot;); //move the fourth slide to initial placeholder
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;$(&quot;.counter&quot;).attr(&quot;data-count&quot;,&quot;2&quot;); //set the counter to 2
&amp;nbsp;&amp;nbsp; &amp;nbsp;});
&amp;nbsp;&amp;nbsp; &amp;nbsp;$(&quot;.d3&quot;).click(function(){
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;var counter = $(&quot;.counter&quot;).attr(&quot;data-count&quot;); //get the counter value
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;if(counter==1){
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;$( &quot;.one&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;slow&quot;); //move the first slide to final placeholder
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.two&quot; ).animate({ &quot;left&quot;: &quot;+=900px&quot; },&quot;slow&quot;); //move the second slide to final placeholder
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $(&quot;.three&quot;).animate({ &quot;left&quot;: &quot;+=450px&quot; }, &quot;slow&quot;); //move the third slide to visible window
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;if(counter==2){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.two&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;slow&quot;); //move the second slide to final placeholder
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.three&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;slow&quot;); //move the third slide to visible window
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;if(counter==4){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.three&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;slow&quot;); //move the third slide to visible window
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.four&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;slow&quot;); //move the fourth slide to initial placeholder
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;$(&quot;.counter&quot;).attr(&quot;data-count&quot;,&quot;3&quot;); //set the counter to 3
&amp;nbsp;&amp;nbsp; &amp;nbsp;});
&amp;nbsp;&amp;nbsp; &amp;nbsp;$(&quot;.d4&quot;).click(function(){
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;var counter = $(&quot;.counter&quot;).attr(&quot;data-count&quot;); //get the counter value
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;if(counter==1){
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;$( &quot;.one&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;slow&quot;); //move the first slide to final placeholder
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.two&quot; ).animate({ &quot;left&quot;: &quot;+=900px&quot; },&quot;slow&quot;); //move the second slide to final placeholder
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $(&quot;.three&quot;).animate({ &quot;left&quot;: &quot;+=900px&quot; }, &quot;slow&quot;); //move the third slide to final placeholder
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $(&quot;.four&quot;).animate({ &quot;left&quot;: &quot;+=450px&quot; }, &quot;slow&quot;); //move the fourth slide to visible window
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;if(counter==2){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.two&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;slow&quot;); //move the second slide to final placeholder
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.three&quot; ).animate({ &quot;left&quot;: &quot;+=900px&quot; },&quot;slow&quot;); //move the third slide to final placeholder
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.four&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;slow&quot;); //move the fourth slide to visible window
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;if(counter==3){
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  $( &quot;.three&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;slow&quot;); //move the third slide to final placeholder
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  $( &quot;.four&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;slow&quot;); //move the fourth slide to visible window
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;$(&quot;.counter&quot;).attr(&quot;data-count&quot;,&quot;4&quot;); //set the counter to 4
&amp;nbsp;&amp;nbsp; &amp;nbsp;});
&amp;nbsp;&amp;nbsp;&amp;nbsp; function moveright(){
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;var counter = $(&quot;.counter&quot;).attr(&quot;data-count&quot;); //get the counter value
&amp;nbsp;&amp;nbsp;  &amp;nbsp;if (counter == 1){ //if 1 is showing 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  $( &quot;.one&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;slow&quot;); //push one out of the visible window to after visible placeholder
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  $( &quot;.two&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;slow&quot;); //push two in the visible window
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  $(&quot;.counter&quot;).attr(&quot;data-count&quot;,&quot;2&quot;); //set the counter value to 2
&amp;nbsp;&amp;nbsp;&amp;nbsp;  }else if(counter==2){ //if 2 is showing
&amp;nbsp;&amp;nbsp;&amp;nbsp;  &amp;nbsp;$( &quot;.two&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;slow&quot;); //push two out of the visible window to after visible placeholder
&amp;nbsp;&amp;nbsp;&amp;nbsp;  &amp;nbsp;$( &quot;.three&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;slow&quot;); //push three in the visible window
&amp;nbsp;&amp;nbsp;&amp;nbsp;  &amp;nbsp;$(&quot;.counter&quot;).attr(&quot;data-count&quot;,&quot;3&quot;); // set the counter value to 3
&amp;nbsp;&amp;nbsp;  &amp;nbsp;}else if(counter==3){ //if three is showing
&amp;nbsp;&amp;nbsp;&amp;nbsp;  &amp;nbsp;$( &quot;.three&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;slow&quot;); //push three out of the visible window to after visible placeholder
&amp;nbsp;&amp;nbsp;&amp;nbsp;  &amp;nbsp;$( &quot;.four&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;slow&quot;); //push four in the visible window
&amp;nbsp;&amp;nbsp;&amp;nbsp;  &amp;nbsp;$(&quot;.counter&quot;).attr(&quot;data-count&quot;,&quot;4&quot;); //set the counter value to 4
&amp;nbsp;&amp;nbsp;&amp;nbsp;  }else if(counter==4){ // if four is showing, this is little tricky
&amp;nbsp;&amp;nbsp;&amp;nbsp;   $( &quot;.one&quot; ).animate({ &quot;left&quot;: &quot;-=900px&quot; },&quot;fast&quot;); // move first div to initial placeholder on the left
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  $( &quot;.two&quot; ).animate({ &quot;left&quot;: &quot;-=900px&quot; },&quot;fast&quot;); // move second div to initial placeholder on the left
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  $( &quot;.three&quot; ).animate({ &quot;left&quot;: &quot;-=900px&quot; },&quot;fast&quot;); // move third div to initial placeholder on the left
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  $( &quot;.four&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;fast&quot;); // move fourth div to initial placeholder on the left
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  //note that the fourth div is pulled only 450px because it is currently in the visible window
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  $( &quot;.one&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;slow&quot;); // move first div to visible window
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  $(&quot;.counter&quot;).attr(&quot;data-count&quot;,&quot;1&quot;); //set the counter value to 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;  }
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; function moveleft(){
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;var counter = $(&quot;.counter&quot;).attr(&quot;data-count&quot;); //get the counter value
&amp;nbsp;&amp;nbsp;&amp;nbsp;  if (counter == 1){ //if the 1st slide is showing
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  $( &quot;.one&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;fast&quot;); //move the first div to the after visible placeholder
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  //since it is showing right now it has to be moved only 450px
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  $( &quot;.two&quot; ).animate({ &quot;left&quot;: &quot;+=900px&quot; },&quot;fast&quot;); // move the second div to the after visible placeholder
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  $( &quot;.three&quot; ).animate({ &quot;left&quot;: &quot;+=900px&quot; },&quot;fast&quot;); //move the third div to after visible placeholder
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  $( &quot;.four&quot; ).animate({ &quot;left&quot;: &quot;+=900px&quot; },&quot;fast&quot;); //move the fourth div to after visible placeholder
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  $( &quot;.four&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;slow&quot;); //move the fourth div to visible window
  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$(&quot;.counter&quot;).attr(&quot;data-count&quot;,&quot;4&quot;); // set the counter to 4the slide
&amp;nbsp;&amp;nbsp;  &amp;nbsp;}else if(counter == 2){ //if second slide is showing
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  $( &quot;.one&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;slow&quot;); //move the first slide to initial placeholder
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  $( &quot;.two&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;slow&quot;); //move the second slide to visible window
&amp;nbsp;&amp;nbsp;&amp;nbsp;  &amp;nbsp;$(&quot;.counter&quot;).attr(&quot;data-count&quot;,&quot;1&quot;); //set the counter to 1
&amp;nbsp;&amp;nbsp;  &amp;nbsp;}else if(counter == 3){ //if third slide is showing
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  $( &quot;.two&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;slow&quot;); //move the second slide to the initial placeholder
  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$( &quot;.three&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;slow&quot;); //move the third slide to visible window
&amp;nbsp;&amp;nbsp;  &amp;nbsp;&amp;nbsp;$(&quot;.counter&quot;).attr(&quot;data-count&quot;,&quot;2&quot;); //update the counter value to 2
  &amp;nbsp;&amp;nbsp;&amp;nbsp;}else if(counter ==4){ //if the fourth slide is showing
&amp;nbsp;&amp;nbsp;  &amp;nbsp;&amp;nbsp;$( &quot;.three&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;slow&quot;); //move the third slide to the intial placeholder
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  $( &quot;.four&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;slow&quot;); //move the fourth slide to visible window
  &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$(&quot;.counter&quot;).attr(&quot;data-count&quot;,&quot;3&quot;); //update the counter value to 3
&amp;nbsp;&amp;nbsp;  &amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;});
&lt;/pre&gt;
&lt;br /&gt;
And that&#39;s that, now we have two carousel which move together.&lt;br /&gt;
&lt;br /&gt;
Please find the fiddle link here&lt;br /&gt;
&lt;iframe width=&quot;100%&quot; height=&quot;300&quot; src=&quot;//jsfiddle.net/amitraya/n2nkqcy4/embedded/&quot; allowfullscreen=&quot;allowfullscreen&quot; frameborder=&quot;0&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://amitraya.blogspot.com/feeds/5831705520029802629/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amitraya.blogspot.com/2015/07/easy-diy-carousel-using-jquery-updated.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7510043426665993888/posts/default/5831705520029802629'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7510043426665993888/posts/default/5831705520029802629'/><link rel='alternate' type='text/html' href='http://amitraya.blogspot.com/2015/07/easy-diy-carousel-using-jquery-updated.html' title='Easy DIY Carousel using Jquery (Updated to include two carousel and slider button)'/><author><name>Amit Raya</name><uri>http://www.blogger.com/profile/10060067214284586056</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7510043426665993888.post-456536318149589338</id><published>2015-07-12T17:22:00.001+05:30</published><updated>2015-07-21T00:45:10.258+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="carousel"/><category scheme="http://www.blogger.com/atom/ns#" term="css"/><category scheme="http://www.blogger.com/atom/ns#" term="diy"/><category scheme="http://www.blogger.com/atom/ns#" term="JQuery"/><category scheme="http://www.blogger.com/atom/ns#" term="simple"/><title type='text'>Easy DIY Carousel using Jquery</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Before we start with the coding let&#39;s examine the concept of this Carousel. The idea is very simple. To explain I have one image and description below:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSgw0ojQw58hUD_wL6o1O0SqmIIN5H22NBi5l2RtY91QTCo2icD3QwjrdAQ-oXIQjas2rdOm4PzgvJsGe4hNexVWMiiOsVTo8UR2Q_VzXDqVwWvUs5EyRBUNXtgBtUsTQ4RzKZxQNHtLPB/s1600/flow+diagram.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;395&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSgw0ojQw58hUD_wL6o1O0SqmIIN5H22NBi5l2RtY91QTCo2icD3QwjrdAQ-oXIQjas2rdOm4PzgvJsGe4hNexVWMiiOsVTo8UR2Q_VzXDqVwWvUs5EyRBUNXtgBtUsTQ4RzKZxQNHtLPB/s640/flow+diagram.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;There are basically three to four steps to building a Carousel using jquery. The details of the concept is given below:&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;1. There has to be a placeholder for divs to start with and this placeholder should not be visible.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;2. There should be a visible window through which each of the div will pass (slide) such that they look like we are rotating images&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;3. There should be another place holder where all these images should go to after passing through the visible window&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;Very simple idea, very simple implementation. Let&#39;s start with the code now.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;First of all let&#39;s define four divs (you can use as many as you like).&lt;/span&gt;&lt;br /&gt;
&lt;code&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;



&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;&quot;&gt;&amp;lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot; &lt;br /&gt;&quot;&lt;a href=&quot;http://www.w3.org/TR/html4/strict.dtd&quot;&gt;http://www.w3.org/TR/html4/strict.dtd&lt;/a&gt;&quot;&amp;gt;&lt;br /&gt;&amp;lt;html xmlns=&quot;&lt;a href=&quot;http://www.w3.org/1999/xhtml&quot;&gt;http://www.w3.org/1999/xhtml&lt;/a&gt;&quot; lang=&quot;en&quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;title&amp;gt;Carousel&amp;lt;/title&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;meta name=&quot;author&quot; content=&quot;amit.raya&quot; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;!-- Date: 2015-07-12 --&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;script src=&quot;jquery-2.1.4.min.js&quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;script src=&quot;jquery-ui.js&quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;mystyle.css&quot;/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;lt;body&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;carousel&quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;main one&quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;inside&quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;main two&quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;inside&quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;main three&quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;inside&quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;main four&quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;inside&quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;pointerleft&quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;img src=&quot;Images/llt.png&quot; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;pointerright&quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;img src=&quot;Images/right.png&quot; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;counter&quot; data-count=&quot;1&quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;/pre&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;After you have defined the four divs let&#39;s color them so that we can recognize which one is which and also try to place all those divs in one location as described in the diagram. Also we need to understand that here div with class carousel is our window, so to start with apart from the first div all other divs will be slid to the left (-450px from the visible&amp;nbsp;window)&amp;nbsp;of the carousel and after they become visible they will be pushed to the right(+450px from the visible window)&amp;nbsp;such that they become invisible again. So our Carousel div has to have overflow hidden and&amp;nbsp;a counter to ensure we are keeping count.&amp;nbsp;So the mystyle.css will look like this:&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;span style=&quot;font-family: Verdana;&quot;&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;&quot;&gt;.carousel{&lt;br /&gt;&amp;nbsp;position:relative; &lt;br /&gt;&amp;nbsp;width:450px;&amp;nbsp;/*width equal to the divs*/&lt;br /&gt;&amp;nbsp;min-height: 550px;&lt;br /&gt;&amp;nbsp;overflow:hidden; /*very important it hides the overflow*/&lt;br /&gt;&amp;nbsp;left:400px; /*to ensure that all divs are hidden*/&lt;br /&gt;}&lt;br /&gt;.main{&lt;br /&gt;&amp;nbsp;position:absolute;&lt;br /&gt;&amp;nbsp;margin-left: -450px;;&lt;br /&gt;}&lt;br /&gt;.inside{&lt;br /&gt;&amp;nbsp;min-width: 400px;&lt;br /&gt;&amp;nbsp;min-height: 500px;&lt;br /&gt;&amp;nbsp;background-color:yellow;&lt;br /&gt;&amp;nbsp;margin:20px;&lt;br /&gt;}&lt;br /&gt;.one{&lt;br /&gt;&amp;nbsp;background-color:green; /*for identification*/&lt;br /&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;&quot;&gt;.two{&lt;br /&gt;&amp;nbsp;background-color:red; /*for identification*/&lt;br /&gt;}&lt;br /&gt;.three{&lt;br /&gt;&amp;nbsp;background-color:grey; /*for identification*/&lt;br /&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;&quot;&gt;.four{&lt;br /&gt;&amp;nbsp;background-color:blue; /*for identification*/&lt;br /&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;&quot;&gt;.pointerright, .pointerleft{&lt;br /&gt;&amp;nbsp;position:absolute;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /*definition for arrow left and right*/&lt;br /&gt;&amp;nbsp;top:230px;&lt;br /&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;
&lt;code&gt;&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;&quot;&gt;.pointerleft{&lt;br /&gt;&amp;nbsp;left:-43px;&lt;br /&gt;}&lt;br /&gt;.pointerright{&lt;br /&gt;&amp;nbsp;right:-43px;&lt;br /&gt;}&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif;&quot;&gt;After this you will only see two arrows in your page. Now let&#39;s do the jquery to start with the rolling.&lt;/span&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;&quot;&gt;
&lt;span style=&quot;font-family: Verdana;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: &amp;quot;Courier New&amp;quot;, Courier, monospace;&quot;&gt;&amp;lt;script&amp;gt;&lt;br /&gt;&amp;nbsp;$(document).ready(function(){&lt;br /&gt;&amp;nbsp;&amp;nbsp;$( &quot;.one&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;slow&quot;); // initially start with 1&lt;br /&gt;&amp;nbsp;&amp;nbsp;$(&quot;.pointerright&quot;).click(function(){ //if the move right pointer is clicked&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; var counter = $(&quot;.counter&quot;).attr(&quot;data-count&quot;); //get the counter value&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if (counter == 1){ //if 1 is showing &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;$( &quot;.one&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;slow&quot;); //push one out of the visible window to after visible placeholder&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; $( &quot;.two&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;slow&quot;); //push two in the visible window&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $(&quot;.counter&quot;).attr(&quot;data-count&quot;,&quot;2&quot;); //set the counter value to 2&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }else if(counter==2){ //if 2 is showing&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; $( &quot;.two&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;slow&quot;); //push two out of the visible window to after visible placeholder&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.three&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;slow&quot;); //push three in the visible window&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; $(&quot;.counter&quot;).attr(&quot;data-count&quot;,&quot;3&quot;); // set the counter value to 3&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }else if(counter==3){ //if three is showing&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.three&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;slow&quot;); //push three out of the visible window to after visible placeholder&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.four&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;slow&quot;); //push four in the visible window&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $(&quot;.counter&quot;).attr(&quot;data-count&quot;,&quot;4&quot;); //set the counter value to 4&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }else if(counter==4){ // if four is showing, this is little tricky&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.one&quot; ).animate({ &quot;left&quot;: &quot;-=900px&quot; },&quot;fast&quot;); // move first div to initial placeholder on the left&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.two&quot; ).animate({ &quot;left&quot;: &quot;-=900px&quot; },&quot;fast&quot;); // move second div to initial placeholder on the left&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.three&quot; ).animate({ &quot;left&quot;: &quot;-=900px&quot; },&quot;fast&quot;); // move third div to initial placeholder on the left&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.four&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;fast&quot;); // move fourth div to initial placeholder on the left&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //note that the fourth div is pulled only 450px because it is currently in the visible window&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.one&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;slow&quot;); // move first div to visible window&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $(&quot;.counter&quot;).attr(&quot;data-count&quot;,&quot;1&quot;); //set the counter value to 1&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;});&lt;br /&gt;&amp;nbsp;&amp;nbsp;$(&quot;.pointerleft&quot;).click(function(){//if the move left pointer is clicked&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;var counter = $(&quot;.counter&quot;).attr(&quot;data-count&quot;); //get the counter value&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (counter == 1){ //if the 1st slide is showing&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.one&quot; ).animate({ &quot;left&quot;: &quot;+=450px&quot; },&quot;fast&quot;); //move the first div to the after visible placeholder&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//since it is showing right now it has to be moved only 450px&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.two&quot; ).animate({ &quot;left&quot;: &quot;+=900px&quot; },&quot;fast&quot;); // move the second div to the after visible placeholder&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.three&quot; ).animate({ &quot;left&quot;: &quot;+=900px&quot; },&quot;fast&quot;); //move the third div to after visible placeholder&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.four&quot; ).animate({ &quot;left&quot;: &quot;+=900px&quot; },&quot;fast&quot;); //move the fourth div to after visible placeholder&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.four&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;slow&quot;); //move the fourth div to visible window&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $(&quot;.counter&quot;).attr(&quot;data-count&quot;,&quot;4&quot;); // set the counter to 4the slide&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }else if(counter == 2){ //if second slide is showing&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.one&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;slow&quot;); //move the first slide to initial placeholder&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.two&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;slow&quot;); //move the second slide to visible window&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $(&quot;.counter&quot;).attr(&quot;data-count&quot;,&quot;1&quot;); //set the counter to 1&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }else if(counter == 3){ //if third slide is showing&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.two&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;slow&quot;); //move the second slide to the initial placeholder&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.three&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;slow&quot;); //move the third slide to visible window&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $(&quot;.counter&quot;).attr(&quot;data-count&quot;,&quot;2&quot;); //update the counter value to 2&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }else if(counter ==4){ //if the fourth slide is showing&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.three&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;slow&quot;); //move the third slide to the intial placeholder&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $( &quot;.four&quot; ).animate({ &quot;left&quot;: &quot;-=450px&quot; },&quot;slow&quot;); //move the fourth slide to visible window&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $(&quot;.counter&quot;).attr(&quot;data-count&quot;,&quot;3&quot;); //update the counter value to 3&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;br /&gt;&amp;nbsp;&amp;nbsp;});&lt;br /&gt;&amp;nbsp;});&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;br /&gt;
&lt;code&gt;&lt;/code&gt;&lt;br /&gt;
&lt;/pre&gt;
Now try to click on either of the arrow and it should work like a charm.&lt;br /&gt;
You can see it works and the code at &lt;a href=&quot;https://jsfiddle.net/amitraya/1pt9swe8/2/&quot;&gt;https://jsfiddle.net/amitraya/1pt9swe8/2/&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://amitraya.blogspot.com/feeds/456536318149589338/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amitraya.blogspot.com/2015/07/easy-diy-carousel-using-jquery.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7510043426665993888/posts/default/456536318149589338'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7510043426665993888/posts/default/456536318149589338'/><link rel='alternate' type='text/html' href='http://amitraya.blogspot.com/2015/07/easy-diy-carousel-using-jquery.html' title='Easy DIY Carousel using Jquery'/><author><name>Amit Raya</name><uri>http://www.blogger.com/profile/10060067214284586056</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSgw0ojQw58hUD_wL6o1O0SqmIIN5H22NBi5l2RtY91QTCo2icD3QwjrdAQ-oXIQjas2rdOm4PzgvJsGe4hNexVWMiiOsVTo8UR2Q_VzXDqVwWvUs5EyRBUNXtgBtUsTQ4RzKZxQNHtLPB/s72-c/flow+diagram.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7510043426665993888.post-1903772398045043964</id><published>2014-09-17T18:22:00.000+05:30</published><updated>2014-09-17T18:22:17.231+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term="asp.net"/><category scheme="http://www.blogger.com/atom/ns#" term="ckeditor"/><category scheme="http://www.blogger.com/atom/ns#" term="free image upload"/><category scheme="http://www.blogger.com/atom/ns#" term="Image upload"/><category scheme="http://www.blogger.com/atom/ns#" term="MVC"/><category scheme="http://www.blogger.com/atom/ns#" term="WYSIWYG"/><title type='text'>CK Editor implement your own Image upload ASP.net MVC</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
We see that many of WYSIWYG have implementation of image upload but when you actually want to implement that most them don&#39;t provide image upload upload right away. However with CK Editor I found a way to implement the image upload using ASP.net. However the coding is very simple so you can implement the same in PHP and other languages also.&lt;br /&gt;
&lt;br /&gt;
First create a project (here I have named it ckeditorfortest). Select default options as given in the images below.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8Fk0iYJBUKR4fktMDxtMN7p6P5dvEnzrmMuxR_t2cQA7Eoq7ZGSUHQcum6o9Qsc1MZcFYqfhGh8H9mlOiZdkPE3NFMgITRVaKttDM5Asp3YZjQcUc-SMXS8BbghhG5YqN8YwtRgoGW7Rr/s1600/Image1.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8Fk0iYJBUKR4fktMDxtMN7p6P5dvEnzrmMuxR_t2cQA7Eoq7ZGSUHQcum6o9Qsc1MZcFYqfhGh8H9mlOiZdkPE3NFMgITRVaKttDM5Asp3YZjQcUc-SMXS8BbghhG5YqN8YwtRgoGW7Rr/s1600/Image1.JPG&quot; height=&quot;387&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhn0IcR4G6L9HRvxudiSnv_TJ0z92-tCau9qQjG_5Etlg5q52S9f2EotlF7ujdMmK7n2OC3xzqoL2YfrCWpFC7L7XoO-aNlSL5hfK7EPfQVZlJbFqp3ExjtLiV1A9_zMomR_U6UT91k54mj/s1600/Image2.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhn0IcR4G6L9HRvxudiSnv_TJ0z92-tCau9qQjG_5Etlg5q52S9f2EotlF7ujdMmK7n2OC3xzqoL2YfrCWpFC7L7XoO-aNlSL5hfK7EPfQVZlJbFqp3ExjtLiV1A9_zMomR_U6UT91k54mj/s1600/Image2.JPG&quot; height=&quot;576&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now visit site&amp;nbsp;&lt;a href=&quot;http://ckeditor.com/download&quot;&gt;http://ckeditor.com/download&lt;/a&gt;&amp;nbsp;and download the standard version as shown in the picture.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFsUhn9FMo22hhEEF8wEWAtnUhGG0xwbpJs7MNihEeAkyNtlrDLGrl8TVyTtJcTj8RsW2ehhaPEYPpzDT9_O2zt2rbeqkwKlkTO8F-WA4yVy34K6QgtntVG-KkWi1W0IBVuGrRt7dO5vV3/s1600/Image3.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFsUhn9FMo22hhEEF8wEWAtnUhGG0xwbpJs7MNihEeAkyNtlrDLGrl8TVyTtJcTj8RsW2ehhaPEYPpzDT9_O2zt2rbeqkwKlkTO8F-WA4yVy34K6QgtntVG-KkWi1W0IBVuGrRt7dO5vV3/s1600/Image3.JPG&quot; height=&quot;284&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
After you have downloaded, upzip the package and include in the root of the project like this&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHWa2Yfaal6QG_hH2DCEUVUmhvC26AWq4woAhwlHwlrEYKWH1HwTX0yaVE44yt3Izmz_AsSnCxgCkxjvAuUuvrUHXCHRYYn8qK18C8mnQTKY_78rOOLIZ-pS19FBnhDr1U6MXWrWkCy65k/s1600/Image4.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHWa2Yfaal6QG_hH2DCEUVUmhvC26AWq4woAhwlHwlrEYKWH1HwTX0yaVE44yt3Izmz_AsSnCxgCkxjvAuUuvrUHXCHRYYn8qK18C8mnQTKY_78rOOLIZ-pS19FBnhDr1U6MXWrWkCy65k/s1600/Image4.JPG&quot; height=&quot;640&quot; width=&quot;246&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
Include the same in the Layout page.&lt;br /&gt;
&lt;br /&gt;
Now to start with, in the index page remove all data and simply post the following lines of code&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-size: 12px; line-height: 14px;&quot;&gt;&amp;lt;textarea id=&quot;editor1&quot; name=&quot;editor1&quot;&amp;gt;&amp;amp;lt;p&amp;amp;gt;Initial value.&amp;amp;lt;/p&amp;amp;gt;&amp;lt;/textarea&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
This is only put a Text Area in the page with id=&quot;editor1&quot; and name=&quot;editor1&quot;. Please ensure that your textarea has id and name, without these attributes CK editor will not work.&lt;br /&gt;
&lt;br /&gt;
Now after doing this put the following code in the Index.cshtml page&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;&quot;&gt;&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
    CKEDITOR.replace(&#39;editor1&#39;);
&amp;lt;/script&amp;gt;
&lt;/pre&gt;
&lt;br /&gt;
This will not enable the editor and when you run the program you will see page like this&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgNnVOwSdr9M8Z_uJ7LCNLVEyNL4qJfFEVxQxu2GecCxKc2R60uv4Tw0ecbTZBvBFwFKIful7Zew45a_utxg2KXYNsojlgaCT37YJAV9A1Bf-sZRi9FwjN8qG_yRn3XwO2UQlupwkF69YP/s1600/Image5.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgNnVOwSdr9M8Z_uJ7LCNLVEyNL4qJfFEVxQxu2GecCxKc2R60uv4Tw0ecbTZBvBFwFKIful7Zew45a_utxg2KXYNsojlgaCT37YJAV9A1Bf-sZRi9FwjN8qG_yRn3XwO2UQlupwkF69YP/s1600/Image5.JPG&quot; height=&quot;276&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
You will see that the WYSIWYG is enabled for the textbox and is working. Now click on the image link&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq1V8gLq2M5oscdDfWjUpE0IzXz1LzqGw8rSOKh28ahF0tQ5ghX9rO1Mj_n_G64YfkfAlnesXZIQDJp8Qr3VY_GDkufECAG0r3uCMcnNV4a-7nfJlJwwy1A6IQsmMzfH-k5Ly9EOtTupk-/s1600/Image6.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em; text-align: center;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhq1V8gLq2M5oscdDfWjUpE0IzXz1LzqGw8rSOKh28ahF0tQ5ghX9rO1Mj_n_G64YfkfAlnesXZIQDJp8Qr3VY_GDkufECAG0r3uCMcnNV4a-7nfJlJwwy1A6IQsmMzfH-k5Ly9EOtTupk-/s1600/Image6.JPG&quot; /&gt;&lt;/a&gt;and then you will see the following modal dialog come up.&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdRSrm8-CZ1Xe9K6vHcr9jphGDq0nnbLW94NK3_rhXAdEWBAij7-FJcybBRQDWwCnBHIRgnujrsKId7vpOUCFjBSWOn_TJ0P-L1h33Dp-DaflTJPRzjY8tovXdj0FBJAByS7uZsik1FA4m/s1600/Image7.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgdRSrm8-CZ1Xe9K6vHcr9jphGDq0nnbLW94NK3_rhXAdEWBAij7-FJcybBRQDWwCnBHIRgnujrsKId7vpOUCFjBSWOn_TJ0P-L1h33Dp-DaflTJPRzjY8tovXdj0FBJAByS7uZsik1FA4m/s1600/Image7.JPG&quot; height=&quot;338&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
As you can see we don&#39;t have option to upload images in this, but you can still provide image URL to include. Now to enable image browsing modify the script we wrote previously in the Index.cshtml to the following:&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;&quot;&gt;&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
    CKEDITOR.replace(&#39;editor1&#39;, {
        filebrowserImageBrowseUrl: &#39;/home/uploadPartial&#39;,
        filebrowserImageUploadUrl: &#39;/home/uploadnow&#39;
    });
&amp;lt;/script&amp;gt;
&lt;/pre&gt;
&lt;br /&gt;
Now after implementing this code, reload the /home/Index page and click on the image icon in the editor toolbar again. What this code basically does is it gives CK editor what is the url where we are going to implement the Image browser and what is the url where we are going to implement the upload functionality.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgf2i1zn_FbU6jvZnX-cCrWB7gmfX78Spbaei3Y9W7CVMhvsTTsd5zVjuNUlIsEVpPeYxOumACCExP9GqES2Z-SBkF_YmNaPi560_z1oOo28cJlE25WPEDgOPn5Jp6In-y6CyWGFFOT7SKN/s1600/Image8.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgf2i1zn_FbU6jvZnX-cCrWB7gmfX78Spbaei3Y9W7CVMhvsTTsd5zVjuNUlIsEVpPeYxOumACCExP9GqES2Z-SBkF_YmNaPi560_z1oOo28cJlE25WPEDgOPn5Jp6In-y6CyWGFFOT7SKN/s1600/Image8.JPG&quot; height=&quot;346&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
Now you can see that we have one new tab call &quot;Upload&quot; and in &quot;Image Info&quot; tab also a new button has come up which says &quot;Browse Server&quot;. In the &quot;Upload&quot; tab you will see option to choose file and send it to server. If you click the same now it will not work nor will the &quot;Browse Server&quot; button in &quot;Image Info&quot; tab.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJi3QxVdnCEGKhFP0eP2Uq0aILpyT2L7-nwzU1X_Zos0dDLBF__lqkIFbvRGedGVPTpqqJ233kbGK9F-wHDIdc_iWsYD-H5CQZ8JyXTx6TzjJbjpOPdCPnp05e2Bf9nTvb0m0A5soEnuVk/s1600/Image9.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjJi3QxVdnCEGKhFP0eP2Uq0aILpyT2L7-nwzU1X_Zos0dDLBF__lqkIFbvRGedGVPTpqqJ233kbGK9F-wHDIdc_iWsYD-H5CQZ8JyXTx6TzjJbjpOPdCPnp05e2Bf9nTvb0m0A5soEnuVk/s1600/Image9.JPG&quot; height=&quot;640&quot; width=&quot;590&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
Now let&#39;s build the functionality for these tabs.&lt;br /&gt;
First let&#39;s create a viewmodel for holding the imageurl(the image url contains the image name also). So right click on the model folder and create class file and name the class file imagesviewmodel.cs. Paste the following code in the viewmodel.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgATqBmE3rPZFhyGF_hfOqTzmf4NzxKOncbHUl4ISBWaQI4GE7gPG0O900avKzWCo7mp0e-DFHnw9c095Y0UVGIFQ71cIPQc4vnCo4MOCG6WfS5LnLjfbjFsvcA8NgEr6FLwrfD9kqmct-_/s1600/Image10.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgATqBmE3rPZFhyGF_hfOqTzmf4NzxKOncbHUl4ISBWaQI4GE7gPG0O900avKzWCo7mp0e-DFHnw9c095Y0UVGIFQ71cIPQc4vnCo4MOCG6WfS5LnLjfbjFsvcA8NgEr6FLwrfD9kqmct-_/s1600/Image10.JPG&quot; height=&quot;402&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;&quot;&gt;public class imagesviewmodel
{
    public string Url { get; set; }
}
&lt;/pre&gt;
&lt;br /&gt;
Next, open the home controller and paste the following code:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;&quot;&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ckeditortest.Models;
using System.IO;

namespace ckeditortest.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }
        public void uploadnow(HttpPostedFileWrapper upload)
        {
            if(upload!=null)
            {
                string ImageName = upload.FileName;
                string path = System.IO.Path.Combine(Server.MapPath(&quot;~/Images/uploads&quot;), ImageName);
                upload.SaveAs(path);
            }
        }
    }
}
&lt;/pre&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
Here apart from the Index action we have added one other action methods. Please ensure to add using System.IO;&lt;br /&gt;
In this new action method which if you realize is same as given in previous jquery script we wrote in Index.cshtml &quot;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;filebrowserImageUploadUrl: &#39;/home/uploadnow&#39;&quot;&lt;/span&gt;, we need to ensure that the name of the action method remains the same. This action will take in a HttpPostedFileWrapper input which we have named upload. The filewrapper will have following information&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj89OYmR4tnH-01LHizBGiclaMtkkOlxXeK7VKuuMm3fSOiQi60LMMM19FnoPqfHqFxxMD1m7XOBEvRCe02H6K1LxNZVnU0KfE-dyApUjUsJly_wqNhbhVL98875zEeRN8Let7iQmjzmsiZ/s1600/Image11.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj89OYmR4tnH-01LHizBGiclaMtkkOlxXeK7VKuuMm3fSOiQi60LMMM19FnoPqfHqFxxMD1m7XOBEvRCe02H6K1LxNZVnU0KfE-dyApUjUsJly_wqNhbhVL98875zEeRN8Let7iQmjzmsiZ/s1600/Image11.JPG&quot; height=&quot;316&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
but we here will be using FileName only. So we will first check if the upload HttpPostedFileWrapper is properly loaded, once that is ascertained we will generate the string path by combining the path where image will be uploaded in the server with the filename. upload.SaveAs(path) will save the image to the local provided. Also ensure that the action returns void because we don&#39;t need to do any action after upload and the page should remain as it is. Now if you try to run the program and go to &quot;Upload&quot; tab and click choose file you can choose file and click on &quot;send it to server&quot; and same will be uploaded to the server.&lt;br /&gt;
Now the upload is complete. Now we will look at how we will insert this image into the WYSIWYG editor.&lt;br /&gt;
For that we will create another action in the home controller as given in the jquery in the Index.cshtml&amp;nbsp;&lt;span style=&quot;background-color: #eeeeee;&quot;&gt;&quot;filebrowserImageBrowseUrl: &#39;/home/uploadPartial&#39;,&quot;&lt;/span&gt;the following code lists the action method.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;&quot;&gt;public ActionResult uploadPartial()
{
     var appData = Server.MapPath(&quot;~/Images/uploads&quot;);
     var images = Directory.GetFiles(appData).Select(x =&amp;gt; new imagesviewmodel
     {
        Url = Url.Content(&quot;/images/uploads/&quot; + Path.GetFileName(x))
     });
     return View(images);
}&lt;/pre&gt;
&lt;br /&gt;
this action method will basically list out all images that are there in the upload directory for the user to choose which image he wants to insert into the WYSIWYG. So the variable &quot;images&quot; take all images that are there in the upload directory along with filename and path. The action method sends this variable to the view.&lt;br /&gt;
Next right click on the action method and create view and name the view uploadPartial.cshtml.&lt;br /&gt;
Paste the following code in the view.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;&quot;&gt;@model IEnumerable&amp;lt;ckeditortest.Models.imagesviewmodel&amp;gt;

@foreach (var image in Model)
{
    &amp;lt;a href=&quot;#&quot; class=&quot;returnImage&quot; data-url=&quot;@Request.Url.GetLeftPart(UriPartial.Authority)@image.Url&quot;&amp;gt;
        &amp;lt;img src=&quot;@image.Url&quot; alt=&quot;Hejsan&quot; id=&quot;#image&quot; data-source=&quot;@image.Url&quot; width=&quot;200&quot; height=&quot;200&quot;/&amp;gt;
    &amp;lt;/a&amp;gt;
}
&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
    $(document).ready(function () {
        $(&quot;.returnImage&quot;).click(&quot;click&quot;, function (e) {
            var urlImage = $(this).attr(&quot;data-url&quot;);
            window.opener.updateValue(&quot;cke_72_textInput&quot;, urlImage);
            window.close();
        });
    });
&amp;lt;/script&amp;gt;&lt;/pre&gt;
&lt;br /&gt;
So upon completing this if you click on the &quot;Browse Server&quot; button, a new page will open which will show all the images in the upload folder. As shown below:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeo8mvgJPoiQCthedr_zbvoIOIaaj3_MdPYffAJixjEc0gvZTMhGFxrTiHP9lwzaBdttZjySRDtowG70vs721sfxXiTq1NbCjh1cya0keMcLwx1aN6gO1iZCHGny6WxVzaKI4SeTy9HmiR/s1600/Image12.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjeo8mvgJPoiQCthedr_zbvoIOIaaj3_MdPYffAJixjEc0gvZTMhGFxrTiHP9lwzaBdttZjySRDtowG70vs721sfxXiTq1NbCjh1cya0keMcLwx1aN6gO1iZCHGny6WxVzaKI4SeTy9HmiR/s1600/Image12.JPG&quot; height=&quot;296&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
To understand what is done in the view, we make this view strongly typed to the viewmodel we create earlier. Now we run through each of the image and append the same to an html anchor. As your will notice we will put in the full path of the image file in data-source attribute. Here&amp;nbsp;@Request.Url.GetLeftPart(UriPartial.Authority) will give the left part of the url of your website. That is if your website url is http://localhost:5938 then this will be returned even if you are http://localhost:5938/home/uploadpartial location. To this we will append the image url which is basically location of the image from the root folder along with image name. So this makes the image clickable. Below we will write some jquery to take the image URL which needs to be returned to &quot;Image Info&quot; tab in the modal dialog where we clicked &quot;Browse server&quot;. What this jquery code does is basically take the image url and send it the opener page which opened this page. So it will be sent one step back and then we close the window.&lt;br /&gt;
As of now if you click on the image nothing will happen. For the image url to come in the &quot;Image Info&quot; tab URL textbox follow the steps below.&lt;br /&gt;
&lt;br /&gt;
Now one final step in the Index.cshtml add one function to get the value of image url from uploadpartial and put that value in the URL textbox in &quot;Image Info&quot; tab. I will give you the full script section so that we don&#39;t get confused.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;&quot;&gt;&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
    CKEDITOR.replace(&#39;editor1&#39;, {
        filebrowserImageBrowseUrl: &#39;/home/uploadPartial&#39;,
        filebrowserImageUploadUrl: &#39;/home/uploadnow&#39;
    });

    function updateValue(id, value) {
        // this gets called from the popup window and updates the field with a new value 
        document.getElementById(id).value = value;
    }
&amp;lt;/script&amp;gt;&lt;/pre&gt;
&lt;br /&gt;
The function updateValue basically takes the id of the element in this case the URL textbox which we send from uploadpartial and the value and inputs the value to the textbox.&lt;br /&gt;
&lt;br /&gt;
Now recompile the code and run now if you go to &quot;Image Info&quot; tab, and click &quot;Browse Server&quot; button you will be shown the uploadpartial, which will basically show all images (clickable) from the upload folder. When you click on any of the image the uploadpartial will be closed and the url of the clicked image will be populated in &quot;URL&quot; textbox of the &quot;Image Info&quot; tab. If you click &quot;Ok&quot; now you will see that the image is inserted in the WYSIWYG editor like in the image below:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMPIZYsKhzelr41nbQzSnLG6blHmbb_rJ10QBnV_MpoZIHv0SKLEzCe9sPzJyWO6oiSEL2CsDyyQI_q7DQBe_9bIDaklJ4r4VHBCZOUOfx2TC9GVGo6UB-UCZcsRHC9fNcDJ4Gp_lgywpg/s1600/Image13.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjMPIZYsKhzelr41nbQzSnLG6blHmbb_rJ10QBnV_MpoZIHv0SKLEzCe9sPzJyWO6oiSEL2CsDyyQI_q7DQBe_9bIDaklJ4r4VHBCZOUOfx2TC9GVGo6UB-UCZcsRHC9fNcDJ4Gp_lgywpg/s1600/Image13.JPG&quot; height=&quot;322&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYIlTemj3pNhVvUct8tpZMlJCfWrwTuZd-HmbeCWid6hLSNGEw30IvdqXkwqKwl0FxSpEQKY6E04GtYUePsbDTp9Bjpa_Y46mHJv3RPqSAGY4m_nEu2N07AHd7s1B_eZ-IRwl6NNPv1IuM/s1600/Image14.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYIlTemj3pNhVvUct8tpZMlJCfWrwTuZd-HmbeCWid6hLSNGEw30IvdqXkwqKwl0FxSpEQKY6E04GtYUePsbDTp9Bjpa_Y46mHJv3RPqSAGY4m_nEu2N07AHd7s1B_eZ-IRwl6NNPv1IuM/s1600/Image14.JPG&quot; height=&quot;260&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;Full Code:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;HomeController.cs&lt;/b&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;&quot;&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ckeditortest.Models;
using System.IO;

namespace ckeditortest.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = &quot;Modify this template to jump-start your ASP.NET MVC application.&quot;;

            return View();
        }
        public ActionResult uploadPartial()
        {
            var appData = Server.MapPath(&quot;~/Images/uploads&quot;);
            var images = Directory.GetFiles(appData).Select(x =&amp;gt; new imagesviewmodel
            {
                Url = Url.Content(&quot;/images/uploads/&quot; + Path.GetFileName(x))
            });
            return View(images);
        }
        public void uploadnow(HttpPostedFileWrapper upload)
        {
            if(upload!=null)
            {
                string ImageName = upload.FileName;
                string path = System.IO.Path.Combine(Server.MapPath(&quot;~/Images/uploads&quot;), ImageName);
                upload.SaveAs(path);
            }

        }
    }
}
&lt;/pre&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;b&gt;imagesviewmodel.cs&lt;/b&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;&quot;&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ckeditortest.Models
{
    public class imagesviewmodel
    {
        public string Url { get; set; }
    }
}&lt;/pre&gt;
&lt;div&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;Index.cshtml&lt;/b&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;&quot;&gt;@{
    ViewBag.Title = &quot;Home Page&quot;;
}

&amp;lt;textarea id=&quot;editor1&quot; name=&quot;editor1&quot;&amp;gt;&amp;amp;lt;p&amp;amp;gt;Initial value.&amp;amp;lt;/p&amp;amp;gt;&amp;lt;/textarea&amp;gt;
&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
    CKEDITOR.replace(&#39;editor1&#39;, {
        filebrowserImageBrowseUrl: &#39;/home/uploadPartial&#39;,
        filebrowserImageUploadUrl: &#39;/home/uploadnow&#39;
    });

    function updateValue(id, value) {
        // this gets called from the popup window and updates the field with a new value 
        document.getElementById(id).value = value;
    }
&amp;lt;/script&amp;gt;&lt;/pre&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;uploadPartial.cshtml&lt;/b&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;&quot;&gt;@model IEnumerable&amp;lt;ckeditortest.Models.imagesviewmodel&amp;gt;

@foreach (var image in Model)
{
    &amp;lt;a href=&quot;#&quot; class=&quot;returnImage&quot; data-url=&quot;@Request.Url.GetLeftPart(UriPartial.Authority)@image.Url&quot;&amp;gt;
        &amp;lt;img src=&quot;@image.Url&quot; alt=&quot;Hejsan&quot; id=&quot;#image&quot; data-source=&quot;@image.Url&quot; width=&quot;200&quot; height=&quot;200&quot;/&amp;gt;
    &amp;lt;/a&amp;gt;
}
&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
    $(document).ready(function () {
        $(&quot;.returnImage&quot;).click(&quot;click&quot;, function (e) {
            var urlImage = $(this).attr(&quot;data-url&quot;);
            //This takes the data value and id of the editor and sends the data(i.e.,image url) back to the caller page
            window.opener.updateValue(&quot;cke_72_textInput&quot;, urlImage);
            window.close();
        });
    });
&amp;lt;/script&amp;gt;&lt;/pre&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;_Layout.cshtml&lt;/b&gt;&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;&quot;&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html lang=&quot;en&quot;&amp;gt;
    &amp;lt;head&amp;gt;
        &amp;lt;meta charset=&quot;utf-8&quot; /&amp;gt;
        &amp;lt;title&amp;gt;@ViewBag.Title - My ASP.NET MVC Application&amp;lt;/title&amp;gt;
        &amp;lt;link href=&quot;~/favicon.ico&quot; rel=&quot;shortcut icon&quot; type=&quot;image/x-icon&quot; /&amp;gt;
        &amp;lt;meta name=&quot;viewport&quot; content=&quot;width=device-width&quot; /&amp;gt;
        &lt;u&gt;&amp;lt;script type=&quot;text/javascript&quot; src=&quot;http://localhost:50972/ckeditor/ckeditor.js&quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;/u&gt;
        &amp;lt;script src=&quot;~/Scripts/jquery-1.8.2.js&quot;&amp;gt;&amp;lt;/script&amp;gt;
        @Styles.Render(&quot;~/Content/css&quot;)
        @Scripts.Render(&quot;~/bundles/modernizr&quot;)
    &amp;lt;/head&amp;gt;
    &amp;lt;body&amp;gt;
        &amp;lt;header&amp;gt;
            &amp;lt;div class=&quot;content-wrapper&quot;&amp;gt;
                &amp;lt;div class=&quot;float-left&quot;&amp;gt;
                    &amp;lt;p class=&quot;site-title&quot;&amp;gt;@Html.ActionLink(&quot;your logo here&quot;, &quot;Index&quot;, &quot;Home&quot;)&amp;lt;/p&amp;gt;
                &amp;lt;/div&amp;gt;
                &amp;lt;div class=&quot;float-right&quot;&amp;gt;
                    &amp;lt;section id=&quot;login&quot;&amp;gt;
                        @Html.Partial(&quot;_LoginPartial&quot;)
                    &amp;lt;/section&amp;gt;
                    &amp;lt;nav&amp;gt;
                        &amp;lt;ul id=&quot;menu&quot;&amp;gt;
                            &amp;lt;li&amp;gt;@Html.ActionLink(&quot;Home&quot;, &quot;Index&quot;, &quot;Home&quot;)&amp;lt;/li&amp;gt;
                            &amp;lt;li&amp;gt;@Html.ActionLink(&quot;About&quot;, &quot;About&quot;, &quot;Home&quot;)&amp;lt;/li&amp;gt;
                            &amp;lt;li&amp;gt;@Html.ActionLink(&quot;Contact&quot;, &quot;Contact&quot;, &quot;Home&quot;)&amp;lt;/li&amp;gt;
                        &amp;lt;/ul&amp;gt;
                    &amp;lt;/nav&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/header&amp;gt;
        &amp;lt;div id=&quot;body&quot;&amp;gt;
            @RenderSection(&quot;featured&quot;, required: false)
            &amp;lt;section class=&quot;content-wrapper main-content clear-fix&quot;&amp;gt;
                @RenderBody()
            &amp;lt;/section&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;footer&amp;gt;
            &amp;lt;div class=&quot;content-wrapper&quot;&amp;gt;
                &amp;lt;div class=&quot;float-left&quot;&amp;gt;
                    &amp;lt;p&amp;gt;&amp;amp;copy; @DateTime.Now.Year - My ASP.NET MVC Application&amp;lt;/p&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/footer&amp;gt;

        @Scripts.Render(&quot;~/bundles/jquery&quot;)
        @RenderSection(&quot;scripts&quot;, required: false)
    &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;
Enjoy free image upload capability in CK editor.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://amitraya.blogspot.com/feeds/1903772398045043964/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amitraya.blogspot.com/2014/09/ck-editor-implement-your-own-image.html#comment-form' title='39 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7510043426665993888/posts/default/1903772398045043964'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7510043426665993888/posts/default/1903772398045043964'/><link rel='alternate' type='text/html' href='http://amitraya.blogspot.com/2014/09/ck-editor-implement-your-own-image.html' title='CK Editor implement your own Image upload ASP.net MVC'/><author><name>Amit Raya</name><uri>http://www.blogger.com/profile/10060067214284586056</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8Fk0iYJBUKR4fktMDxtMN7p6P5dvEnzrmMuxR_t2cQA7Eoq7ZGSUHQcum6o9Qsc1MZcFYqfhGh8H9mlOiZdkPE3NFMgITRVaKttDM5Asp3YZjQcUc-SMXS8BbghhG5YqN8YwtRgoGW7Rr/s72-c/Image1.JPG" height="72" width="72"/><thr:total>39</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7510043426665993888.post-4375806664662391398</id><published>2014-05-18T05:56:00.001+05:30</published><updated>2014-05-18T06:39:14.965+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term=".NET"/><category scheme="http://www.blogger.com/atom/ns#" term="asp.net"/><category scheme="http://www.blogger.com/atom/ns#" term="Captcha"/><category scheme="http://www.blogger.com/atom/ns#" term="Email"/><category scheme="http://www.blogger.com/atom/ns#" term="Export to Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="MVC"/><category scheme="http://www.blogger.com/atom/ns#" term="Razor"/><category scheme="http://www.blogger.com/atom/ns#" term="ReCaptcha"/><category scheme="http://www.blogger.com/atom/ns#" term="ViewModel"/><title type='text'>Export to Excel, Send Email and Captcha Implementation in ASP.NET MVC</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Create a project, name it &quot;ExportToExcelSendEmailandRecaptcha&quot;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTtGxY_o69ZTzDtAXWjkxCB-kjJke7A_5meGhTFU7epKFymI1LH6K8EYzxKBOgTtiiVnPTGevnf_Onx-qerS_IQUxus_zLnYLSZvV5GPHdr0J-fw2Rh-c9CDTZJwN2BW1fH2x-gh7ln6cI/s1600/1.+Create+Project.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTtGxY_o69ZTzDtAXWjkxCB-kjJke7A_5meGhTFU7epKFymI1LH6K8EYzxKBOgTtiiVnPTGevnf_Onx-qerS_IQUxus_zLnYLSZvV5GPHdr0J-fw2Rh-c9CDTZJwN2BW1fH2x-gh7ln6cI/s1600/1.+Create+Project.JPG&quot; height=&quot;245&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
After you add the project Select &quot;MVC&quot; project and click &quot;Ok&quot;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4GyU2zKrqKTMaBVtyw2y5aDkoLhKuEStfqgg7jGOBRlkTvYEmeSV-NyE7_E3NUYJPnNtibSvdcXRzIjAfSz0djrprMOXKLH9FuLRUy77xCdYZ1JjEYTcrP79P1hFqS1Y3sboehonyreVo/s1600/2.+selectMVC.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4GyU2zKrqKTMaBVtyw2y5aDkoLhKuEStfqgg7jGOBRlkTvYEmeSV-NyE7_E3NUYJPnNtibSvdcXRzIjAfSz0djrprMOXKLH9FuLRUy77xCdYZ1JjEYTcrP79P1hFqS1Y3sboehonyreVo/s1600/2.+selectMVC.JPG&quot; height=&quot;297&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
You will see the following solution is added&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLYZj6vB-cGbn4iLlLobIjt03Lzglf_UaXT1N2QsJNHUIbjBUwQSAKiwhV0lxl9KdGhfBfhmlbLEbYTrRxJIGgA6xVm8d-PLr-tQuT_s3TxqFVvNRr9vCwr1YEqYRE_7UmuM6URGBdc9QE/s1600/3.+solutionexplorer.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgLYZj6vB-cGbn4iLlLobIjt03Lzglf_UaXT1N2QsJNHUIbjBUwQSAKiwhV0lxl9KdGhfBfhmlbLEbYTrRxJIGgA6xVm8d-PLr-tQuT_s3TxqFVvNRr9vCwr1YEqYRE_7UmuM6URGBdc9QE/s1600/3.+solutionexplorer.JPG&quot; height=&quot;320&quot; width=&quot;220&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
Add a ViewModel Folder and right click and add class. As class as &quot;Instructor.cs&quot;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaha8lDFikZuvGJqe2QHedmknCMgZgMrEPYdtCvyJSJItjcVlxUY9fPj8HynfwUfYsg81xzqTkxAt0NiQE6-tIvjjmrDwl2916GR5wTgCoO0cgQacGHjL_DN45ECoxJsH5OjUXebx9Ybdd/s1600/4.Create+view+model.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaha8lDFikZuvGJqe2QHedmknCMgZgMrEPYdtCvyJSJItjcVlxUY9fPj8HynfwUfYsg81xzqTkxAt0NiQE6-tIvjjmrDwl2916GR5wTgCoO0cgQacGHjL_DN45ECoxJsH5OjUXebx9Ybdd/s1600/4.Create+view+model.JPG&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
After this define the model, please remember for this demo the model is not important so I am not going to database and creating the model. I will only be using this viewModel as my model.&lt;br /&gt;
Add the following code in &quot;Instructor.cs&quot;&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); color: black; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ExportToExcelSendEmailandRecaptcha.ViewModel
{
&amp;nbsp; &amp;nbsp;public class Instructor
&amp;nbsp; &amp;nbsp;{
&amp;nbsp; &amp;nbsp; &amp;nbsp;public string FirstName { get; set; }
&amp;nbsp; &amp;nbsp; &amp;nbsp;public string LastName { get; set; }
&amp;nbsp; &amp;nbsp; &amp;nbsp;public string Email { get; set; }
&amp;nbsp; &amp;nbsp; &amp;nbsp;public string Mobile { get; set; }
&amp;nbsp; &amp;nbsp;}
}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;code&gt;&lt;br /&gt;&lt;/code&gt;
Now that we have created the class for model, let&#39;s go to HomeController.cs and make the following changes to display our index page as it would come from the database. Add the following code in index action method.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); color: black; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-family: Trebuchet MS, sans-serif; font-size: x-small;&quot;&gt;public ActionResult Index()
{

&amp;nbsp; &amp;nbsp; var instructors = new List&amp;lt;Instructor&amp;gt;
&amp;nbsp; &amp;nbsp; {
 &amp;nbsp; &amp;nbsp; new Instructor{FirstName=&quot;Carson&quot;, LastName = &quot;Alexander&quot;, Email=&quot;carson.alexander@xyz.com&quot;, Mobile=&quot;8888888888&quot;},
 &amp;nbsp; &amp;nbsp; new Instructor{FirstName=&quot;Meredith&quot;, LastName = &quot;Alonso&quot;, Email=&quot;carson.alexander@xyz.com&quot;, Mobile=&quot;8888888888&quot;},
 &amp;nbsp; &amp;nbsp; new Instructor{FirstName=&quot;Arturo&quot;, LastName = &quot;Anand&quot;, Email=&quot;carson.alexander@xyz.com&quot;, Mobile=&quot;8888888888&quot;},
&amp;nbsp; &amp;nbsp; new Instructor{FirstName=&quot;Gytis&quot;, LastName = &quot;Barzdukas&quot;, Email=&quot;carson.alexander@xyz.com&quot;, Mobile=&quot;8888888888&quot;},
 &amp;nbsp; new Instructor{FirstName=&quot;Yan&quot;, LastName = &quot;Li&quot;, Email=&quot;carson.alexander@xyz.com&quot;, Mobile=&quot;8888888888&quot;},
 &amp;nbsp; new Instructor{FirstName=&quot;Peggy&quot;, LastName = &quot;Justice&quot;, Email=&quot;carson.alexander@xyz.com&quot;, Mobile=&quot;8888888888&quot;},
 &amp;nbsp; new Instructor{FirstName=&quot;Laura&quot;, LastName = &quot;Norman&quot;, Email=&quot;carson.alexander@xyz.com&quot;, Mobile=&quot;8888888888&quot;},
 &amp;nbsp; new Instructor{FirstName=&quot;Nino&quot;, LastName = &quot;Olivetto&quot;, Email=&quot;carson.alexander@xyz.com&quot;, Mobile=&quot;8888888888&quot;}
&amp;nbsp; &amp;nbsp; };
 &amp;nbsp; TempData[&quot;instructors&quot;] = instructors;
 &amp;nbsp; return View(instructors);
}&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Lucida Console&#39;, Monaco, fixed, monospace; font-size: 12px;&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
This should give us the normal kind of view whenever we open an index view, but for that you need to right click on the action and click view. Let&#39;s make the view linked to the viewmodel we had created for making it easy to implement.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzdYIWZ8waTK_SeocCQ2UJ_XJzS9kdb8BMSrjmbyE5qvc5YRTgjRGC9IRFYbh3X9GP7M_j3uXf5aU0KiphhiJenM6F66VvjJCrx4p27Bdemup7VMQvKs_fhxdy0hENkhRlB15MFauQlqMm/s1600/6.+Add+View.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzdYIWZ8waTK_SeocCQ2UJ_XJzS9kdb8BMSrjmbyE5qvc5YRTgjRGC9IRFYbh3X9GP7M_j3uXf5aU0KiphhiJenM6F66VvjJCrx4p27Bdemup7VMQvKs_fhxdy0hENkhRlB15MFauQlqMm/s1600/6.+Add+View.JPG&quot; height=&quot;400&quot; width=&quot;362&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1Ft2pmbQCDZKLoryDUXSDXdCRuKhJoi_mb1Jj_YCa8PtPlsC8qjfhNV9LfxLMY_uKDn4WeYa9oq_NCluiQCFHAzrjHj82f3YPlNh4nkS5UxVv70Ii8WPR0aPVu_gFPJhSB5tdzolgu4L6/s1600/7.Add+view+1.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj1Ft2pmbQCDZKLoryDUXSDXdCRuKhJoi_mb1Jj_YCa8PtPlsC8qjfhNV9LfxLMY_uKDn4WeYa9oq_NCluiQCFHAzrjHj82f3YPlNh4nkS5UxVv70Ii8WPR0aPVu_gFPJhSB5tdzolgu4L6/s1600/7.Add+view+1.JPG&quot; height=&quot;246&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheZ-CvcjJ1asTgxbyr4Z6zI2sDUDjjhe8vK0CGrUwo5DOgD9kVHzClVDLV9d4QqlGgiSg1IlXfNgMg5-NQng2zK4RSbTB_gbOiCLpZBrKABQphZ4dPYxZdJqPHfdBUrPcNF5HbS-Ol27er/s1600/8.View+Added.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheZ-CvcjJ1asTgxbyr4Z6zI2sDUDjjhe8vK0CGrUwo5DOgD9kVHzClVDLV9d4QqlGgiSg1IlXfNgMg5-NQng2zK4RSbTB_gbOiCLpZBrKABQphZ4dPYxZdJqPHfdBUrPcNF5HbS-Ol27er/s1600/8.View+Added.JPG&quot; height=&quot;114&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
Now click run and this is the page you should see&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9QQrzopRqiAhoRjtJoufrj0QOr4z_8NYRIFeURNELjg4MMTVjqzLcK6UK4C_GU8ti4a3ymZzy-yznVb71tw6Kd4WKszSIubLS1-sahi4jQYpUscTV6S7lgdQ4BtWRGHBg6gJ60BQg3ijQ/s1600/9.View+Added1.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9QQrzopRqiAhoRjtJoufrj0QOr4z_8NYRIFeURNELjg4MMTVjqzLcK6UK4C_GU8ti4a3ymZzy-yznVb71tw6Kd4WKszSIubLS1-sahi4jQYpUscTV6S7lgdQ4BtWRGHBg6gJ60BQg3ijQ/s1600/9.View+Added1.JPG&quot; height=&quot;276&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now add the Export to excel button to the view, write the following code in the view:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVKn-GXf7g6gtp7-MiXWe9QTpnOMRxxTVAJYlRXykXZpGI4T1aJcf46C_jmR7WcOSsx49OD3RtiI8Vk27MZgxVfNfx_swM_8BLRxnPn_-ZraoyCvVjwWJ7qn7NpwsghysmaUzfxIfoaQuG/s1600/10.+Add+export+button.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVKn-GXf7g6gtp7-MiXWe9QTpnOMRxxTVAJYlRXykXZpGI4T1aJcf46C_jmR7WcOSsx49OD3RtiI8Vk27MZgxVfNfx_swM_8BLRxnPn_-ZraoyCvVjwWJ7qn7NpwsghysmaUzfxIfoaQuG/s1600/10.+Add+export+button.JPG&quot; height=&quot;112&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
Now your view should look like this.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjc3abf5PU0XLjfA7DYsLs9g9150v95B3Qo2TUDeZnu_vQWlAA4hi6arMKAwRNWPC-gpv3OWQo_Fm9Ac_srWrlPRHmpsjvBDztWbZssSbcyui5pjk7jPn2y7T2UdcC_WI9GdF4yWIsw-JIE/s1600/13.+Index+2.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjc3abf5PU0XLjfA7DYsLs9g9150v95B3Qo2TUDeZnu_vQWlAA4hi6arMKAwRNWPC-gpv3OWQo_Fm9Ac_srWrlPRHmpsjvBDztWbZssSbcyui5pjk7jPn2y7T2UdcC_WI9GdF4yWIsw-JIE/s1600/13.+Index+2.JPG&quot; height=&quot;276&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now let&#39;s implement the export to excel button. In the controller add the following code.&lt;br /&gt;
In the action definition add&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-JZ3QfdzPEw5Pf70a1aQ-2z-FPjkyOCb0tPU75f2ezfrPNLWQu4ZIA08gqk_FQJ1vqDWHo45WO6C8WsHGIhKsLMalKK7h4YL-IyRdAwY1NMbxFQUQsToSbDDWQiPbpFRtTmNmVCWeRLzh/s1600/14.addtoaction.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-JZ3QfdzPEw5Pf70a1aQ-2z-FPjkyOCb0tPU75f2ezfrPNLWQu4ZIA08gqk_FQJ1vqDWHo45WO6C8WsHGIhKsLMalKK7h4YL-IyRdAwY1NMbxFQUQsToSbDDWQiPbpFRtTmNmVCWeRLzh/s1600/14.addtoaction.JPG&quot; height=&quot;330&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now add the reuse object with the following code, please also note the reference added&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); color: black; font-family: &#39;Andale Mono&#39;, &#39;Lucida Console&#39;, Monaco, fixed, monospace; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
&lt;span style=&quot;background-color: yellow;&quot;&gt;using ExportToExcelSendEmailandRecaptcha.ViewModel;&lt;/span&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;using System.Web.UI;&lt;/span&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;using System.Web.UI.WebControls;&lt;/span&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;using System.IO;&lt;/span&gt;

namespace ExportToExcelSendEmailandRecaptcha.Reuse
{
&amp;nbsp; &amp;nbsp; public class Reuse
&amp;nbsp; &amp;nbsp; {
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; internal void actualExport(List&amp;lt;Instructor&amp;gt; instructors, HttpResponseBase resp)
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; GridView gv = new GridView();
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gv.DataSource = instructors;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gv.DataBind();
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; resp.ClearContent();
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; resp.Buffer = true;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; resp.AddHeader(&quot;content-disposition&quot;, &quot;attachment; filename=&quot; + &quot;instructor&quot; + &quot;.xls&quot;);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; resp.ContentType = &quot;application/msexcel&quot;;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; resp.Charset = &quot;&quot;;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; StringWriter sw = new StringWriter();
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; HtmlTextWriter htw = new HtmlTextWriter(sw);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; gv.RenderControl(htw);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; resp.Output.Write(sw.ToString());
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; resp.Flush();
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; resp.End();
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }
&amp;nbsp; &amp;nbsp; }
}&lt;span style=&quot;font-size: 12px;&quot;&gt;

&lt;/span&gt;&lt;span style=&quot;font-size: x-small;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
Now you are ready, click on the button and you should be asked to save the excel sheet.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQi2tzUMGsO2rJH2NXi4XBNTVsB-GeYONSJ-ub6kriZs4Oz7_ZrC_dlhioNgV7g_4MoIieuaD3ctE_b5eYeE50b6Fh-kA74kubzVpnV_2inJwPuWfCnCj7bKPBCbA9X6kaHCGSPqtMwNr5/s1600/15.+Exportsuccess.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQi2tzUMGsO2rJH2NXi4XBNTVsB-GeYONSJ-ub6kriZs4Oz7_ZrC_dlhioNgV7g_4MoIieuaD3ctE_b5eYeE50b6Fh-kA74kubzVpnV_2inJwPuWfCnCj7bKPBCbA9X6kaHCGSPqtMwNr5/s1600/15.+Exportsuccess.JPG&quot; height=&quot;324&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
You can save the excel sheet and you will see that you have the same table as in index&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKEE61w9dRJYrLWkagwi7UbKM049it9Tu29GDdEnCmU5gE6je1WpWfinl1uhRJgQYpcmQ_KWDDk-5g6W1yUjjomwVrUryYAPlM_RUU7fd1LwVpxFhshi7Hk35KcHoO7T_4q3QlHlYvM-6_/s1600/15.+Exportsuccess1.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKEE61w9dRJYrLWkagwi7UbKM049it9Tu29GDdEnCmU5gE6je1WpWfinl1uhRJgQYpcmQ_KWDDk-5g6W1yUjjomwVrUryYAPlM_RUU7fd1LwVpxFhshi7Hk35KcHoO7T_4q3QlHlYvM-6_/s1600/15.+Exportsuccess1.JPG&quot; height=&quot;230&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now let&#39;s move to the other section for sending Email using hotmail (Now Outlook) using your code. The idea is the administrator will get email when comment will be updated by anyone in the website.&lt;br /&gt;
&lt;br /&gt;
First in the Reuse.cs add the following reference&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); color: black; font-family: &#39;Andale Mono&#39;, &#39;Lucida Console&#39;, Monaco, fixed, monospace; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;using System.Net;
using System.Net.Mail;

//Then add this code below the actualExport function:


internal bool sendEmail(string strReceiver, string strSubject, string strComment)
{
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;try
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; MailMessage mailMessage = new MailMessage();
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mailMessage.From = new MailAddress(&quot;defAdminEmail@hotmail.com&quot;, &quot;&lt;span style=&quot;background-color: orange;&quot;&gt;anyAlias&lt;/span&gt;&quot;);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mailMessage.To.Add(strReceiver);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mailMessage.Subject = strSubject;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mailMessage.Body = strComment;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mailMessage.IsBodyHtml = true;

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SmtpClient smtpClient = new SmtpClient();
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; smtpClient.Host = &quot;smtp-mail.outlook.com&quot;;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; smtpClient.Port = 587;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; smtpClient.EnableSsl = true;

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NetworkCredential networkCredential = new NetworkCredential();
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; networkCredential.UserName = &quot;abc@hotmail.com&quot;;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; networkCredential.Password = &quot;abcde&quot;;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; smtpClient.UseDefaultCredentials = true;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; smtpClient.Credentials = networkCredential;

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; smtpClient.Send(mailMessage);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return true;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;catch (Exception e)
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return false;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }
&amp;nbsp;}
&lt;span style=&quot;font-size: 12px;&quot;&gt;


&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
anyAlias highlighted in orange is the display name with which the email will be sent. Now in the HomeController add the contact function&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); color: black; font-family: &#39;Andale Mono&#39;, &#39;Lucida Console&#39;, Monaco, fixed, monospace; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;public ActionResult Contact()
{
&amp;nbsp; &amp;nbsp;&amp;nbsp;ViewBag.Message = TempData[&quot;submitMessage&quot;];
&amp;nbsp; &amp;nbsp; return View();
}&lt;span style=&quot;font-size: 12px;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
Now create another ViewModel as follows and name it ContactWithEmail.cs. I am creating this ViewModel even for one single component in the page to show that we can have components exported in email and also to make it easier for Captcha implementation, which I will talk about later.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); color: black; font-family: &#39;Andale Mono&#39;, &#39;Lucida Console&#39;, Monaco, fixed, monospace; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace ContosoUniversity.ViewModels
{
&amp;nbsp; &amp;nbsp; public class ContactWithEmail
&amp;nbsp; &amp;nbsp; {
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; [Required(ErrorMessage = &quot;Please enter Comment&quot;)]
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; public string Comment { get; set; }
&amp;nbsp; &amp;nbsp; }
}&lt;span style=&quot;font-size: 12px;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
now build the code to add strongly typed view with the ViewModel. Select the following options:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfCY9FTh2p0NgUhdSL_cKTrB8qpvWkR9cqxW-6IT31ckkpyMaBkcZQhyNqR6Ft9KyFdG8wWhVoiwXnNVW_1CbqLBlZBjLL1P6SON8QwU3WMf7NoLhsu_39hLBvSrsKXtcFaW6Z_9jcH2RB/s1600/16.MakeStronglyTypedView.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfCY9FTh2p0NgUhdSL_cKTrB8qpvWkR9cqxW-6IT31ckkpyMaBkcZQhyNqR6Ft9KyFdG8wWhVoiwXnNVW_1CbqLBlZBjLL1P6SON8QwU3WMf7NoLhsu_39hLBvSrsKXtcFaW6Z_9jcH2RB/s1600/16.MakeStronglyTypedView.JPG&quot; height=&quot;394&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
With this an edit form will be generate called Contact.cshtml. In the generated code you will see&amp;nbsp;@Html.EditorFor. Please change that to&amp;nbsp;@Html.TextAreaFor. The code will look like the following now&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); color: black; font-family: &#39;Andale Mono&#39;, &#39;Lucida Console&#39;, Monaco, fixed, monospace; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;@model ExportToExcelSendEmailandRecaptcha.ViewModel.ContactWithEmail
@{
&amp;nbsp; &amp;nbsp; ViewBag.Title = &quot;Contact&quot;;
}

&amp;lt;h2&amp;gt;Contact&amp;lt;/h2&amp;gt;
@using (Html.BeginForm())
{
&amp;nbsp; &amp;nbsp; @Html.AntiForgeryToken()
&amp;nbsp; &amp;nbsp;&amp;nbsp;
&amp;nbsp; &amp;nbsp; &amp;lt;div class=&quot;form-horizontal&quot;&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;h4&amp;gt;ContactWithEmail&amp;lt;/h4&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;hr /&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @Html.ValidationSummary(true, &quot;&quot;, new { @class = &quot;text-danger&quot; })
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;@ViewBag.Message
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;div class=&quot;form-group&quot;&amp;gt;
  &amp;nbsp; &amp;nbsp; &amp;nbsp; @Html.LabelFor(model =&amp;gt; model.Comment, htmlAttributes: new { @class = &quot;control-label col-md-2&quot; })
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @Html.TextAreaFor(model =&amp;gt; model.Comment, new { htmlAttributes = new { @class = &quot;form-control&quot; }, rows=&quot;5&quot;, cols=&quot;50&quot; })
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @Html.ValidationMessageFor(model =&amp;gt; model.Comment, &quot;&quot;, new { @class = &quot;text-danger&quot; })
&amp;nbsp; &amp;nbsp; &amp;lt;/div&amp;gt;

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;div class=&quot;form-group&quot;&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;div class=&quot;col-md-offset-2 col-md-10&quot;&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;input type=&quot;submit&quot; value=&quot;Save&quot; class=&quot;btn btn-default&quot; /&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/div&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/div&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/div&amp;gt;

}

&amp;lt;div&amp;gt;
&amp;nbsp; &amp;nbsp; @Html.ActionLink(&quot;Back to List&quot;, &quot;Index&quot;)
&amp;lt;/div&amp;gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
Now let&#39;s create the post action for contact with the following code&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); color: black; font-family: &#39;Andale Mono&#39;, &#39;Lucida Console&#39;, Monaco, fixed, monospace; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;[HttpPost]
public ActionResult Contact(ContactWithEmail contact)
{
&amp;nbsp; &amp;nbsp; &amp;nbsp;if (ModelState.IsValid)
&amp;nbsp; &amp;nbsp; &amp;nbsp; {
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (ReUse.sendEmail(&quot;abc@hotmail.com&quot;, &quot;From Website&quot;, contact.Comment))
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;TempData[&quot;submitMessage&quot;] = &quot;You have successfully submitted your message, you will be contacted shortly&quot;;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return RedirectToAction(&quot;contact&quot;);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;TempData[&quot;submitMessage&quot;] = &quot;Sorry currently your email couldn&#39;t be sent&quot;;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return RedirectToAction(&quot;contact&quot;);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return View(contact);
}&lt;span style=&quot;font-size: 12px;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
Please try to put a comment and send message now to see it will work :)&lt;br /&gt;
&lt;br /&gt;
Now let&#39;s move to captcha implementation, we don&#39;t want bots saving comments do we. For this we need to go to NuGet and get ReCaptcha plugin. Open NuGet and search for ReCaptcha as below:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPDgDa7ZzFaOnzta2EkxFVs8SsY-YbMAk0TUWT4k_rLzuo_NbJbzxWdp-jPBfnBX_RQApuu5IW4VBBLszIkf4vs4m8TWdzPvPMMnYRQTUyD1KxnkwSGx7fEeXg5p9xzNUnnowIrXI6dE2d/s1600/17.Recaptcha.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjPDgDa7ZzFaOnzta2EkxFVs8SsY-YbMAk0TUWT4k_rLzuo_NbJbzxWdp-jPBfnBX_RQApuu5IW4VBBLszIkf4vs4m8TWdzPvPMMnYRQTUyD1KxnkwSGx7fEeXg5p9xzNUnnowIrXI6dE2d/s1600/17.Recaptcha.JPG&quot; height=&quot;426&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Click on install and follow through. Now add the following to the reference in HomeController.cs&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); color: black; font-family: &#39;Andale Mono&#39;, &#39;Lucida Console&#39;, Monaco, fixed, monospace; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;using Recaptcha.Web;
using Recaptcha.Web.Mvc;
using System.Threading.Tasks;&lt;span style=&quot;font-size: 12px;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
Then make the following changes to the Web.config file that is on the outermost solution&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); color: black; font-family: &#39;Andale Mono&#39;, &#39;Lucida Console&#39;, Monaco, fixed, monospace; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&amp;lt;appSettings&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;lt;add key=&quot;webpages:Version&quot; value=&quot;3.0.0.0&quot; /&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;lt;add key=&quot;webpages:Enabled&quot; value=&quot;false&quot; /&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;lt;add key=&quot;ClientValidationEnabled&quot; value=&quot;true&quot; /&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;lt;add key=&quot;UnobtrusiveJavaScriptEnabled&quot; value=&quot;true&quot; /&amp;gt;
&amp;nbsp; &amp;nbsp;&lt;span style=&quot;background-color: yellow;&quot;&gt; &amp;lt;add key=&quot;recaptchaPublicKey&quot; value=&quot;6LcYP-YSAAAAAG4Pir8LWAtarfN7ZfEaGgJ9H7Gv&quot; /&amp;gt;&lt;/span&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;lt;add key=&quot;recaptchaPrivateKey&quot; value=&quot;6LcYP-YSAAAAAHq5pXcy5_PB7nY-AB-P-4hVG9rO&quot; /&amp;gt;&lt;/span&gt;
&amp;lt;/appSettings&amp;gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
In the contact.cshtml make the following changes (highlighted in yellow)&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); color: black; font-family: &#39;Andale Mono&#39;, &#39;Lucida Console&#39;, Monaco, fixed, monospace; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;@model ExportToExcelSendEmailandRecaptcha.ViewModel.ContactWithEmail
&lt;span style=&quot;background-color: yellow;&quot;&gt;@using Recaptcha.Web.Mvc;&lt;/span&gt;
@{
&amp;nbsp; &amp;nbsp; ViewBag.Title = &quot;Contact&quot;;
}

&amp;lt;h2&amp;gt;Contact&amp;lt;/h2&amp;gt;

@using (Html.BeginForm())
{
&amp;nbsp; &amp;nbsp; @Html.AntiForgeryToken()

&amp;nbsp; &amp;nbsp; &amp;lt;div class=&quot;form-horizontal&quot;&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;h4&amp;gt;ContactWithEmail&amp;lt;/h4&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;hr /&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @Html.ValidationSummary(true, &quot;&quot;, new { @class = &quot;text-danger&quot; })
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @ViewBag.Message
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;div class=&quot;form-group&quot;&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @Html.LabelFor(model =&amp;gt; model.Comment, htmlAttributes: new { @class = &quot;control-label col-md-2&quot; })
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @Html.TextAreaFor(model =&amp;gt; model.Comment, new { htmlAttributes = new { @class = &quot;form-control&quot; }, rows=&quot;5&quot;, cols=&quot;50&quot; })
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @Html.ValidationMessageFor(model =&amp;gt; model.Comment, &quot;&quot;, new { @class = &quot;text-danger&quot; })
&amp;nbsp; &amp;nbsp; &amp;lt;/div&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;span style=&quot;background-color: yellow;&quot;&gt;&amp;lt;div class=&quot;form-group&quot;&amp;gt;&lt;/span&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @Html.Label(&quot; &amp;nbsp; &quot;, new { @class = &quot;col-sm-2 control-label&quot; })&lt;/span&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @Html.Recaptcha(theme: Recaptcha.Web.RecaptchaTheme.Clean)&lt;/span&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/div&amp;gt;&lt;/span&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;div class=&quot;form-group&quot;&amp;gt;
 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;div class=&quot;col-md-offset-2 col-md-10&quot;&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;input type=&quot;submit&quot; value=&quot;Save&quot; class=&quot;btn btn-default&quot; /&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/div&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;/div&amp;gt;
&amp;nbsp; &amp;nbsp; &amp;lt;/div&amp;gt;
}



&amp;lt;div&amp;gt;

&amp;nbsp; &amp;nbsp; @Html.ActionLink(&quot;Back to List&quot;, &quot;Index&quot;)

&amp;lt;/div&amp;gt;&lt;span style=&quot;font-size: 12px;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
Your contact.cshtml should now look like this&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6Bd-6UomABmGk3SZAxWrkqDWUhyVA82lP_9cv6ewoJO-leKMiQC7BtSEAG5j9D210eqywos4mZCZIOoK7VvA3eastEvSaw4d8tQRNKORY-Mcjktg00lo89vNjm8ABTlj4lQhAekMklVeA/s1600/18.FormCaptcha.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6Bd-6UomABmGk3SZAxWrkqDWUhyVA82lP_9cv6ewoJO-leKMiQC7BtSEAG5j9D210eqywos4mZCZIOoK7VvA3eastEvSaw4d8tQRNKORY-Mcjktg00lo89vNjm8ABTlj4lQhAekMklVeA/s1600/18.FormCaptcha.JPG&quot; height=&quot;348&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now let&#39;s implement the final code for checking the captcha. This will change the post action method for contact in the HomeController.cs&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); color: black; font-family: &#39;Andale Mono&#39;, &#39;Lucida Console&#39;, Monaco, fixed, monospace; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;[HttpPost]
public async Task&amp;lt;ActionResult&amp;gt; Contact(ContactWithEmail contact)
{
&amp;nbsp; &amp;nbsp; &amp;nbsp;RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();

&amp;nbsp; &amp;nbsp; &amp;nbsp;if (string.IsNullOrEmpty(recaptchaHelper.Response))
&amp;nbsp; &amp;nbsp; &amp;nbsp;{
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ModelState.AddModelError(&quot;&quot;, &quot;Captcha answer cannot be empty&quot;);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return View(contact);
&amp;nbsp; &amp;nbsp; &amp;nbsp;}
&amp;nbsp; &amp;nbsp; &amp;nbsp;RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync();
&amp;nbsp; &amp;nbsp; &amp;nbsp;if (recaptchaResult != RecaptchaVerificationResult.Success)
&amp;nbsp; &amp;nbsp; {
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ModelState.AddModelError(&quot;&quot;, &quot;Incorrect captcha error&quot;);
&amp;nbsp; &amp;nbsp; }


&amp;nbsp; &amp;nbsp; if (ModelState.IsValid)
&amp;nbsp; &amp;nbsp; {
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if (ReUse.sendEmail(&quot;abc@hotmail.com&quot;, &quot;From Website&quot;, contact.Comment))
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;TempData[&quot;submitMessage&quot;] = &quot;You have successfully submitted your message, you will be contacted shortly&quot;;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return RedirectToAction(&quot;contact&quot;);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; TempData[&quot;submitMessage&quot;] = &quot;Sorry currently your email couldn&#39;t be sent&quot;;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; return RedirectToAction(&quot;contact&quot;);
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }
&amp;nbsp; &amp;nbsp; }
&amp;nbsp; &amp;nbsp; return View(contact);
}&lt;span style=&quot;font-size: 12px;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
This is the final implementation. I couldn&#39;t find a way to upload my code, if you need, please contact me I will be happy to share. However, I have also pasted all my code below, please don&#39;t forget to add NuGet reference for recaptcha.&lt;br /&gt;
&lt;br /&gt;
Final Codes:&lt;br /&gt;
HomeController.cs&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&lt;span style=&quot;line-height: 14px;&quot;&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ExportToExcelSendEmailandRecaptcha.ViewModel;
using System.Collections;
using ExportToExcelSendEmailandRecaptcha.Reuse;
using Recaptcha.Web;
using Recaptcha.Web.Mvc;
using System.Threading.Tasks;

namespace ExportToExcelSendEmailandRecaptcha.Controllers
{
    public class HomeController : Controller
    {
        Reuse.Reuse ReUse = new Reuse.Reuse();

        public ActionResult Index(bool? toExport=false)
        {
            var instructors = new List&amp;lt;Instructor&amp;gt;
            {
                new Instructor{FirstName=&quot;Carson&quot;, LastName = &quot;Alexander&quot;, Email=&quot;carson.alexander@xyz.com&quot;, Mobile=&quot;8888888888&quot;},
                new Instructor{FirstName=&quot;Meredith&quot;, LastName = &quot;Alonso&quot;, Email=&quot;carson.alexander@xyz.com&quot;, Mobile=&quot;8888888888&quot;},
                new Instructor{FirstName=&quot;Arturo&quot;, LastName = &quot;Anand&quot;, Email=&quot;carson.alexander@xyz.com&quot;, Mobile=&quot;8888888888&quot;},
                new Instructor{FirstName=&quot;Gytis&quot;, LastName = &quot;Barzdukas&quot;, Email=&quot;carson.alexander@xyz.com&quot;, Mobile=&quot;8888888888&quot;},
                new Instructor{FirstName=&quot;Yan&quot;, LastName = &quot;Li&quot;, Email=&quot;carson.alexander@xyz.com&quot;, Mobile=&quot;8888888888&quot;},
                new Instructor{FirstName=&quot;Peggy&quot;, LastName = &quot;Justice&quot;, Email=&quot;carson.alexander@xyz.com&quot;, Mobile=&quot;8888888888&quot;},
                new Instructor{FirstName=&quot;Laura&quot;, LastName = &quot;Norman&quot;, Email=&quot;carson.alexander@xyz.com&quot;, Mobile=&quot;8888888888&quot;},
                new Instructor{FirstName=&quot;Nino&quot;, LastName = &quot;Olivetto&quot;, Email=&quot;carson.alexander@xyz.com&quot;, Mobile=&quot;8888888888&quot;}
            };
            
            //Not for first time load, will be triggered only when you click on export to excel
            if (toExport == true)
            {
                ReUse.actualExport(instructors.ToList(),this.Response);
            }
            return View(instructors);
        }

        public ActionResult Contact()
        {
            //For error or success message display when redirected
            ViewBag.Message = TempData[&quot;submitMessage&quot;];
            return View();
        }

        [HttpPost]
        public async Task&amp;lt;ActionResult&amp;gt; Contact(ContactWithEmail contact)
        {
            RecaptchaVerificationHelper recaptchaHelper = this.GetRecaptchaVerificationHelper();

            if (string.IsNullOrEmpty(recaptchaHelper.Response))
            {
                ModelState.AddModelError(&quot;&quot;, &quot;Captcha answer cannot be empty&quot;);
                return View(contact);
            }
            RecaptchaVerificationResult recaptchaResult = await recaptchaHelper.VerifyRecaptchaResponseTaskAsync();

            if (recaptchaResult != RecaptchaVerificationResult.Success)
            {
                ModelState.AddModelError(&quot;&quot;, &quot;Incorrect captcha error&quot;);
            }

            if (ModelState.IsValid)
            {
                if (ReUse.sendEmail(&quot;abc@hotmail.com&quot;, &quot;From Website&quot;, contact.Comment))
                {
                    TempData[&quot;submitMessage&quot;] = &quot;You have successfully submitted your message, you will be contacted shortly&quot;;
                    return RedirectToAction(&quot;contact&quot;);
                }
                else
                {
                    TempData[&quot;submitMessage&quot;] = &quot;Sorry currently your email couldn&#39;t be sent&quot;;
                    return RedirectToAction(&quot;contact&quot;);
                }

            }
            return View(contact);
        }
    }
}&lt;/span&gt;&lt;span style=&quot;font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace;&quot;&gt;&lt;span style=&quot;line-height: 14px;&quot;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
Index.cshtml&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&lt;span style=&quot;line-height: 14px;&quot;&gt;@model IEnumerable&amp;lt;ExportToExcelSendEmailandRecaptcha.ViewModel.Instructor&amp;gt;

@{
    ViewBag.Title = &quot;Index&quot;;
}

&amp;lt;h2&amp;gt;Index&amp;lt;/h2&amp;gt;
@using (Html.BeginForm(&quot;Index&quot;,&quot;Home&quot;,FormMethod.Get))
{
    @Html.Hidden(&quot;toExport&quot;,true)
    &amp;lt;input type=&quot;submit&quot; class=&quot;btn btn-danger&quot; value=&quot;Export to Excel&quot; /&amp;gt;
}


&amp;lt;p&amp;gt;
    
&amp;lt;/p&amp;gt;
&amp;lt;table class=&quot;table&quot;&amp;gt;
    &amp;lt;tr&amp;gt;
        &amp;lt;th&amp;gt;
            @Html.DisplayNameFor(model =&amp;gt; model.FirstName)
        &amp;lt;/th&amp;gt;
        &amp;lt;th&amp;gt;
            @Html.DisplayNameFor(model =&amp;gt; model.LastName)
        &amp;lt;/th&amp;gt;
        &amp;lt;th&amp;gt;
            @Html.DisplayNameFor(model =&amp;gt; model.Email)
        &amp;lt;/th&amp;gt;
        &amp;lt;th&amp;gt;
            @Html.DisplayNameFor(model =&amp;gt; model.Mobile)
        &amp;lt;/th&amp;gt;
        &amp;lt;th&amp;gt;&amp;lt;/th&amp;gt;
    &amp;lt;/tr&amp;gt;

@foreach (var item in Model) {
    &amp;lt;tr&amp;gt;
        &amp;lt;td&amp;gt;
            @Html.DisplayFor(modelItem =&amp;gt; item.FirstName)
        &amp;lt;/td&amp;gt;
        &amp;lt;td&amp;gt;
            @Html.DisplayFor(modelItem =&amp;gt; item.LastName)
        &amp;lt;/td&amp;gt;
        &amp;lt;td&amp;gt;
            @Html.DisplayFor(modelItem =&amp;gt; item.Email)
        &amp;lt;/td&amp;gt;
        &amp;lt;td&amp;gt;
            @Html.DisplayFor(modelItem =&amp;gt; item.Mobile)
        &amp;lt;/td&amp;gt;
        &amp;lt;td&amp;gt;
            @Html.ActionLink(&quot;Edit&quot;, &quot;Edit&quot;, new { /* id=item.PrimaryKey */ }) |
            @Html.ActionLink(&quot;Details&quot;, &quot;Details&quot;, new { /* id=item.PrimaryKey */ }) |
            @Html.ActionLink(&quot;Delete&quot;, &quot;Delete&quot;, new { /* id=item.PrimaryKey */ })
        &amp;lt;/td&amp;gt;
    &amp;lt;/tr&amp;gt;
}

&amp;lt;/table&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
Reuse.cs&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&lt;span style=&quot;line-height: 14px;&quot;&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ExportToExcelSendEmailandRecaptcha.ViewModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Net;
using System.Net.Mail;

namespace ExportToExcelSendEmailandRecaptcha.Reuse
{
    public class Reuse
    {
        internal void actualExport(List&amp;lt;Instructor&amp;gt; instructors, HttpResponseBase resp)
        {
            //We will use grid to put the same in excel by creating XML which will be saved as excel
            //create new grid handle
            GridView gv = new GridView();
            //assign the instructor table as datasource
            gv.DataSource = instructors;
            //bind the data source with the grid handle
            gv.DataBind();
            resp.ClearContent();
            resp.Buffer = true;
            //This gives the name of the excel sheet, inplace of &quot;instructor&quot; you can have different filename
            //If you want different file name you can have this also sent from the controller
            resp.AddHeader(&quot;content-disposition&quot;, &quot;attachment; filename=&quot; + &quot;instructor&quot; + &quot;.xls&quot;);
            resp.ContentType = &quot;application/msexcel&quot;;
            resp.Charset = &quot;&quot;;
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            gv.RenderControl(htw);
            resp.Output.Write(sw.ToString());
            resp.Flush();
            resp.End();
        }

        internal bool sendEmail(string strReceiver, string strSubject, string strComment)
        {
            try
            {
                //create the mail message handle, this is given by System.Net.Mail
                MailMessage mailMessage = new MailMessage();
                //This gives the from address for sender
                //First is for the email address and second is for display name
                //Display name can be any but email has to be valid
                mailMessage.From = new MailAddress(&quot;abc@hotmail.com&quot;, &quot;Contosso University&quot;);
                //Add email to be sent to address
                mailMessage.To.Add(strReceiver);
                //Subject for the email
                mailMessage.Subject = strSubject;
                //Body of the email
                mailMessage.Body = strComment;
                //type for email body here I have selected to be HTML
                mailMessage.IsBodyHtml = true;

                //Define smtp handle given by System.Net
                SmtpClient smtpClient = new SmtpClient();
                //Define host, this keeps changing, so check your setting for hotmail
                //Alternatively you can use your gmail also ask smtp server
                smtpClient.Host = &quot;smtp-mail.outlook.com&quot;;
                smtpClient.Port = 587;
                smtpClient.EnableSsl = true;

                NetworkCredential networkCredential = new NetworkCredential();
                networkCredential.UserName = &quot;abc@hotmail.com&quot;;
                networkCredential.Password = &quot;abcabc&quot;;
                smtpClient.UseDefaultCredentials = true;
                smtpClient.Credentials = networkCredential;

                smtpClient.Send(mailMessage);
                return true;
            }
            catch (Exception e)
            {
                return false;
            }
        }
    }
}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
ContactWithEmail.cs&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&lt;span style=&quot;line-height: 14px;&quot;&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace ExportToExcelSendEmailandRecaptcha.ViewModel
{
    public class ContactWithEmail
    {
        /*You need not necessary add this ViewModel if you have only one column*/
        [Required(ErrorMessage = &quot;Please enter Comment&quot;)]
        public string Comment { get; set; }
    }
}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
Contact.cshtml&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&lt;span style=&quot;line-height: 14px;&quot;&gt;@model ExportToExcelSendEmailandRecaptcha.ViewModel.ContactWithEmail

@*Recaptcha will work only with public and private key. Please register in website*@
@using Recaptcha.Web.Mvc;
@*Recaptcha will work only with public and private key. Please register in website*@


@{
    ViewBag.Title = &quot;Contact&quot;;
}

&amp;lt;h2&amp;gt;Contact&amp;lt;/h2&amp;gt;

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken()
    
    &amp;lt;div class=&quot;form-horizontal&quot;&amp;gt;
        &amp;lt;h4&amp;gt;ContactWithEmail&amp;lt;/h4&amp;gt;
        &amp;lt;hr /&amp;gt;
        @Html.ValidationSummary(true, &quot;&quot;, new { @class = &quot;text-danger&quot; })
        @ViewBag.Message
        &amp;lt;div class=&quot;form-group&quot;&amp;gt;
            @Html.LabelFor(model =&amp;gt; model.Comment, htmlAttributes: new { @class = &quot;control-label col-md-2&quot; })
            @Html.TextAreaFor(model =&amp;gt; model.Comment, new { htmlAttributes = new { @class = &quot;form-control&quot; }, rows=&quot;5&quot;, cols=&quot;50&quot; })
            @Html.ValidationMessageFor(model =&amp;gt; model.Comment, &quot;&quot;, new { @class = &quot;text-danger&quot; })
        &amp;lt;/div&amp;gt;
        &amp;lt;div class=&quot;form-group&quot;&amp;gt;
            @Html.Label(&quot;   &quot;, new { @class = &quot;col-sm-2 control-label&quot; })
            @Html.Recaptcha(theme: Recaptcha.Web.RecaptchaTheme.Clean)
        &amp;lt;/div&amp;gt;
        &amp;lt;div class=&quot;form-group&quot;&amp;gt;
            &amp;lt;div class=&quot;col-md-offset-2 col-md-10&quot;&amp;gt;
                &amp;lt;input type=&quot;submit&quot; value=&quot;Save&quot; class=&quot;btn btn-default&quot; /&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
}

&amp;lt;div&amp;gt;
    @Html.ActionLink(&quot;Back to List&quot;, &quot;Index&quot;)
&amp;lt;/div&amp;gt;

&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://amitraya.blogspot.com/feeds/4375806664662391398/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amitraya.blogspot.com/2014/05/export-to-excel-send-email-and-captcha.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7510043426665993888/posts/default/4375806664662391398'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7510043426665993888/posts/default/4375806664662391398'/><link rel='alternate' type='text/html' href='http://amitraya.blogspot.com/2014/05/export-to-excel-send-email-and-captcha.html' title='Export to Excel, Send Email and Captcha Implementation in ASP.NET MVC'/><author><name>Amit Raya</name><uri>http://www.blogger.com/profile/10060067214284586056</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgTtGxY_o69ZTzDtAXWjkxCB-kjJke7A_5meGhTFU7epKFymI1LH6K8EYzxKBOgTtiiVnPTGevnf_Onx-qerS_IQUxus_zLnYLSZvV5GPHdr0J-fw2Rh-c9CDTZJwN2BW1fH2x-gh7ln6cI/s72-c/1.+Create+Project.JPG" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7510043426665993888.post-6869374863560340069</id><published>2012-09-13T17:45:00.000+05:30</published><updated>2012-09-13T17:45:32.833+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term=".NET"/><category scheme="http://www.blogger.com/atom/ns#" term="asp.net"/><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET MVC"/><category scheme="http://www.blogger.com/atom/ns#" term="dot net"/><category scheme="http://www.blogger.com/atom/ns#" term="JQuery"/><category scheme="http://www.blogger.com/atom/ns#" term="JQuery ASP.NET MVC"/><category scheme="http://www.blogger.com/atom/ns#" term="modal dialog form"/><category scheme="http://www.blogger.com/atom/ns#" term="modal form"/><category scheme="http://www.blogger.com/atom/ns#" term="MVC"/><category scheme="http://www.blogger.com/atom/ns#" term="Razor"/><category scheme="http://www.blogger.com/atom/ns#" term="VWD 2010"/><title type='text'>Modal Dialog form view using JQuery ASP.Net MVC</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
Modal dialog form view&amp;nbsp;using JQuery:&lt;br /&gt;
&lt;br /&gt;
Create a project in VWD.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipvAWOWQ9LPkr7JxLoG8HIOedrwJKpTLwsKznED2Q_hGs7sDHiNsO2FFn2W_wlNZrPU6QFK8-yu68EXbUD2QhQKg3Gq44V8_OCUGT9CEXJM-OUTpNh3m5da0QPZ7A7dJQDsfE4zzjXGIID/s1600/Create+Project.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;441&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipvAWOWQ9LPkr7JxLoG8HIOedrwJKpTLwsKznED2Q_hGs7sDHiNsO2FFn2W_wlNZrPU6QFK8-yu68EXbUD2QhQKg3Gq44V8_OCUGT9CEXJM-OUTpNh3m5da0QPZ7A7dJQDsfE4zzjXGIID/s640/Create+Project.JPG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
for convinence sake we will call it Modal_JQuery_ASPdotNet_MVC. You can name your project to you liking.&lt;br /&gt;
&lt;br /&gt;
Now click Ok button. Select Internet Project and click Ok. The view engine I use is Razor, so I have selected Razor as my view engine.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgbUEaDYW_DOmNDwpnCb_TEwJUekkLZwY0bS5-cqpa7pOXgbJsO_g6yQ2otUESL6OOrSfMgc6UPdbkcVhSOfBSGFpBCQGvKCG23JcEemOWkMqoOthbUYBaa8C06TgR0DxqBhxwbFsF0_hy/s1600/Select+Internet+Proj.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;578&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgbUEaDYW_DOmNDwpnCb_TEwJUekkLZwY0bS5-cqpa7pOXgbJsO_g6yQ2otUESL6OOrSfMgc6UPdbkcVhSOfBSGFpBCQGvKCG23JcEemOWkMqoOthbUYBaa8C06TgR0DxqBhxwbFsF0_hy/s640/Select+Internet+Proj.JPG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now the basic set up is done. We will have the following items created in Solution explorer for us to use.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZtS0yS9yOGPPQIZS6VG380MhTKEvpL5gCHZUCVBb-SGbiuAJcAKufJFhvDmH_jYEEN_UdMcKF5ntniB_PFACFIn24ebi19IN4ayWvhV9-UYPZ4r2y30JduIMPhctik6tMchyphenhyphen9X691rt35/s1600/Solution+Explorer.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZtS0yS9yOGPPQIZS6VG380MhTKEvpL5gCHZUCVBb-SGbiuAJcAKufJFhvDmH_jYEEN_UdMcKF5ntniB_PFACFIn24ebi19IN4ayWvhV9-UYPZ4r2y30JduIMPhctik6tMchyphenhyphen9X691rt35/s640/Solution+Explorer.JPG&quot; width=&quot;318&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div align=&quot;left&quot; class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Now as you can see you already have Home controller and Views for Home created. Since the modal doesn&#39;t have to do much with controller and view (apart from handling the logic and showing the view) we will work on Home controller and Home View to show our Modal dialog.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
The idea of this sample is to show a partial view as modal dialog. So we also need to create a partial view which will be displayed as modal dialog. Right click on ~/views/shared/ folder and add&amp;nbsp;a partial view.&amp;nbsp; As given below:&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjba5ynXMYEkEong8SPIdAtygEHMaag3ozhPCwHnquEBWaycNbYXvxaQ-C9sBdspcGfRLc2eEygQciiDeN-nZmvIuwXNPeZaGqOjkMPEBcHEbQ2hRtfdMpZw-VZKTGttG_eXYLt-0g2j8tk/s1600/Add+view.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;370&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjba5ynXMYEkEong8SPIdAtygEHMaag3ozhPCwHnquEBWaycNbYXvxaQ-C9sBdspcGfRLc2eEygQciiDeN-nZmvIuwXNPeZaGqOjkMPEBcHEbQ2hRtfdMpZw-VZKTGttG_eXYLt-0g2j8tk/s640/Add+view.jpg&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIT6TD27rQ3Z0SHr-s57ly55Ez6TmYDQR9bbMFo26yczVO_3gQ0uEqgRYHqV2VBQYYdWbjs5aH7pF7aCj0a4JxWf8hBcdXFFwo_IHx5QaCbXJN3ut-gikACMxB9lClqCJKjaFgVgUt3ix6/s1600/contactusviewpartial.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;630&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjIT6TD27rQ3Z0SHr-s57ly55Ez6TmYDQR9bbMFo26yczVO_3gQ0uEqgRYHqV2VBQYYdWbjs5aH7pF7aCj0a4JxWf8hBcdXFFwo_IHx5QaCbXJN3ut-gikACMxB9lClqCJKjaFgVgUt3ix6/s640/contactusviewpartial.JPG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;Now write the code for what you want displayed in the modal dialog. Say we are working on making a Contact Us form. So let&#39;s add code for the same.&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); color: black; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;&lt;em&gt;&amp;lt;&lt;/em&gt;label for=&quot;Name&quot;&amp;gt;Name:&amp;lt;/label &amp;gt;&amp;lt;br /&amp;gt;

&amp;lt;input id=&quot;Namecontact&quot; name=&quot;Name&quot; type=&quot;text&quot; /&amp;gt;&amp;lt;br /&amp;gt;

&amp;lt;label for=&quot;email&quot;&amp;gt;Email:&amp;lt;/label&amp;gt;&amp;lt;br /&amp;gt;

&amp;lt;input id=&quot;emailcontact&quot; name=&quot;email&quot; type=&quot;text&quot; /&amp;gt;&amp;lt;br /&amp;gt;

&amp;lt;label for=&quot;message&quot;&amp;gt;Message:&amp;lt;/label&amp;gt;&amp;lt;br /&amp;gt;

&amp;lt;textarea id=&quot;messagecontact&quot; name=&quot;message&quot;&amp;gt;&amp;lt;/textarea&amp;gt;

&amp;lt;input class=&quot;close&quot; name=&quot;submit&quot; type=&quot;submit&quot; value=&quot;Submit&quot; /&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;code&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
&lt;em&gt;
&lt;/em&gt;&lt;/span&gt;&lt;/code&gt;&lt;br /&gt;
&lt;br /&gt;
code for the modal is complete with this partial implementation. Now all that remains is writing JQuery involved in respresenting this partial as modal dialog.&lt;code&gt;&lt;/code&gt;
&lt;br /&gt;
Now to start with the JQuery code. Open Index view in ~/Views/Home/. This view is already created by VWD when we created the project. Now for simplicity sake please delete all the below selected code in Index.cshtml.&lt;br /&gt;
&lt;em&gt;
&lt;br /&gt;
&lt;/em&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSkeCSGtSgvjNhxzDwX-40lk3-_r7Ge4VUdOSVqdnwXi44cvM659lo2tDVK388OOILqXeb1d1mJsScLT15Kqc2huQ4earF1HyZw5eMjlSEfKsG_00OdBu4CrA_6peQyLAfKEG3pdkoertu/s1600/Remove+selected+code+2.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;em&gt;&lt;img border=&quot;0&quot; height=&quot;434&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjSkeCSGtSgvjNhxzDwX-40lk3-_r7Ge4VUdOSVqdnwXi44cvM659lo2tDVK388OOILqXeb1d1mJsScLT15Kqc2huQ4earF1HyZw5eMjlSEfKsG_00OdBu4CrA_6peQyLAfKEG3pdkoertu/s640/Remove+selected+code+2.JPG&quot; width=&quot;640&quot; /&gt;&lt;/em&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Now start with the Jquery first include JQuery library, JQuery UI and JQuery Unobtrusive ajax extensions to your code. You can do that by adding the following code:&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); color: black; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;
&amp;lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery-1.4.4.js&quot;)&quot; type=&quot;text/javascript&quot;&amp;gt;
&amp;lt;/script&amp;gt;
&amp;lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery-ui-1.8.11.js&quot;)&quot; type=&quot;text/javascript&quot;&amp;gt;
&amp;lt;/script&amp;gt;
&amp;lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery.validate.js&quot;)&quot; type=&quot;text/javascript&quot;&amp;gt;
&amp;lt;/script&amp;gt;
&amp;lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery.validate.unobtrusive.js&quot;)&quot; type=&quot;text/javascript&quot;&amp;gt;
&amp;lt;/script&amp;gt;
&amp;lt;script src=&quot;@Url.Content(&quot;~/Scripts/jquery.unobtrusive-ajax.js&quot;)&quot; type=&quot;text/javascript&quot;&amp;gt;
&amp;lt;/script&amp;gt;
&lt;/code&gt;
&lt;/pre&gt;
&lt;span style=&quot;color: #a31515; font-family: Consolas; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #a31515; font-family: Consolas; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #a31515; font-family: Consolas; font-size: x-small;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: #a31515; font-family: Consolas; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #a31515; font-family: Consolas; font-size: x-small;&quot;&gt;&lt;span style=&quot;color: #a31515; font-family: Consolas; font-size: x-small;&quot;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;Now moving forward we will create a action link on click of which will open the modal dialog.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); color: black; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;
@Html.ActionLink(&quot;Contact US&quot;,&quot;ContactUs&quot;,&quot;Home&quot;,null,
new {@class=&quot;openDialog&quot;,data_dialog_id=&quot;emailDialog&quot;,data_dialog_title=&quot;contactus&quot;})
&lt;/code&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;em&gt;
&lt;/em&gt;&lt;br /&gt;
&lt;br /&gt;
Let&#39;s break that down for you. @Html.Action generates anchor tag in HTML for us. It has many overload out of which the one we are using has the following component&lt;br /&gt;
&lt;br /&gt;
@Html.ActionLink(&quot;Text of the&amp;nbsp;link&quot;,&quot;Action to be called&quot;, &quot;Controller in which action is present&quot;, &quot;route values&quot;, &quot;Html attributes to be assigned to anchor tag&quot;)&lt;br /&gt;
So&amp;nbsp;here we have&amp;nbsp;said create a anchor tag with text Contact US which will call the action name ContactUs in controller Home. It doesn&#39;t have&amp;nbsp;any route values that is to say we are not passing any parameter to the action and its Html attributes are as follows:&lt;br /&gt;
it&#39;s class name is openDialog&lt;br /&gt;
it&#39;s data_dialog_id attribute is emailDialog&lt;br /&gt;
it&#39;s data_dialog_title attribute is contactus&lt;br /&gt;
&lt;br /&gt;
so now below given HTML will be generated when you do view source:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); color: black; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;
&amp;lt;a class=&quot;openDialog&quot; data-dialog-id=&quot;emailDialog&quot; data-dialog-title=&quot;contactus&quot; href=&quot;/Home/ContactUs&quot;&amp;gt;Contact US&amp;lt;/a&amp;gt;
&lt;/code&gt;
&lt;/pre&gt;
&lt;br /&gt;
Note: data_dialog_id in @Html.ActionLink is converted to data-dialog-id when anchor tag is created. This happens automatically.&lt;br /&gt;
Also add a div to display the result thrown from the dailog to be displayed:&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); color: black; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;
&amp;lt;div id=&quot;result&quot;&amp;gt;&amp;lt;/div&amp;gt;
&lt;/code&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
Now write JQuery to create the modal. (please remove comment in case this doesn&#39;t work, the comments are added for understanding and don&#39;t play any role in code.)&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); color: black; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;
&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
    //Below code will clear cache
    $.ajaxSetup({ cache: false }); 
    //Below code will run the JQuery when document is ready. 
    $(document).ready(function () {
    //Below code will append a click event to the class openDialog 
    //which we assigned to the anchor previously
        $(&quot;.openDialog&quot;).live(&quot;click&quot;, function (e) {
            //Below code will prevent default action from occuring
            //when openDialog anchor is clicked
            e.preventDefault();
            //This is the actual implementation of the dailog
            $(&quot;&amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;&quot;)
            //To the div created for dialog we will add class named dialog
            //this is done so that we can refer to the dialog later
            //we will see this in a short while why it is important
            .addClass(&quot;dialog&quot;)
            //add attribute add id attribute
            //note id attribute is assigned the same value as data-dialog-id
            //attribute in openDialog anchor
            .attr(&quot;id&quot;,$(this).attr(&quot;data-dialog-id&quot;))
            //below code appends this div to body
            .appendTo(&quot;body&quot;)
            //below code describes the attribute for the dialog
            .dialog({
                //below code assigns title to the dialog
                //here we use same title as data-dialog-title attribute
                //in openDialog anchor tag
                title: $(this).attr(&quot;data-dialog-title&quot;),
                //this will append code to close the dialog
                //and also put close cross(x) in dialog
                //we press ESC key in keyboard will also close dialog
                close: function () { $(this).remove() },
                //below code defines that the dialog is modal dialog
                modal:true
            })
            //below code says take href from openDialog anchor
            //which is /Home/ContactUs and load it to the modal dialog
            .load(this.href);
        });
    });
&amp;lt;/script&amp;gt;
&lt;/code&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
Now a small controller code needs to be written to open the modal dialog.&lt;br /&gt;
In Home controller write the following code:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); font-family: &amp;quot;Andale Mono&amp;quot;, &amp;quot;Lucida Console&amp;quot;, Monaco, fixed, monospace; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;public &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;ActionResult&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt; ContactUs()&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;   return&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt; PartialView(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&quot;ContactUs&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
Now, since we are refering the JQuery library in our Index file we need to clear JQuery reference from our _Layout.cshtml file. so in _Layout.cshtml find the line which says @Scripts.Render&lt;br /&gt;
(&quot;~/bundles/jquery&quot;) and comment it. The way to comment using razor syntax is as follows:&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); font-family: &amp;quot;Andale Mono&amp;quot;, &amp;quot;Lucida Console&amp;quot;, Monaco, fixed, monospace; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;@*&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;@Scripts.Render(&quot;~/bundles/jquery&quot;)&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;*@&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;span style=&quot;font-family: Consolas; font-size: x-small;&quot;&gt;&lt;span style=&quot;font-family: Consolas; font-size: x-small;&quot;&gt;Note:Applies only to guys using VWD2012&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
Now for final touch so that your modal looks good include JQuery UI CSS in the _Layout.cshtml.&lt;br /&gt;
&lt;br /&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); font-family: &amp;quot;Andale Mono&amp;quot;, &amp;quot;Lucida Console&amp;quot;, Monaco, fixed, monospace; font-size: 12px; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;
&lt;span style=&quot;font-size: small;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&amp;lt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;link&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;rel&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;=&quot;stylesheet&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;type&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;=&quot;text/css&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;href&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;=&quot;../../Content/jquery-ui.css&quot;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;/&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;br /&gt;
And for simplicity sake I suggest you to remove the default style sheet&#39;s section which defines ui-dialog for ajax login because it conflicts with the JQuery UI CSS.&lt;br /&gt;
Note: Applies only to guys using VWD 2012.&lt;br /&gt;
&lt;br /&gt;
Now our dialog can be opened and if we press ESC key the dialog will close.(screenshot below).
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwStRDBGkjOHABw9Q7zS4p9cXM1ZPzL5ejfhB2XExhgsJW2gAE0g0mQjHWkxpsvc2hvxxOvy1iC2anyTHuKv4gbqDaErkazXGmz_B8gS1LxhtQphwm0VIms5CMshJE1fiLJh4A7kZAqhhi/s1600/modal+dialog+with+partial.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;346&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwStRDBGkjOHABw9Q7zS4p9cXM1ZPzL5ejfhB2XExhgsJW2gAE0g0mQjHWkxpsvc2hvxxOvy1iC2anyTHuKv4gbqDaErkazXGmz_B8gS1LxhtQphwm0VIms5CMshJE1fiLJh4A7kZAqhhi/s640/modal+dialog+with+partial.JPG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Note you can see that the partial ContactUs.cshtml which we created previously is reflected as dialog here. We can have any kind of form shown as dialog in this way.&lt;br /&gt;
&lt;br /&gt;
Now what happens if I want to take the dialog&#39;s data after submit is clicked and process the data and also show it in the page as updated.&lt;br /&gt;
&lt;br /&gt;
We will do that now.&lt;br /&gt;
&lt;br /&gt;
Before we move on with the JQuery let&#39;s first create a ContactUs post method controller where we will do the logic processing.&amp;nbsp; The controller will look like this.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); font-family: &amp;quot;Andale Mono&amp;quot;, &amp;quot;Lucida Console&amp;quot;, Monaco, fixed, monospace; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;HttpPost&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;public&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt; &lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;ActionResult&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt; ContactUs(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;string&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt; name,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;string&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt; email,&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;string&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt; message)&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;{&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;    &lt;/span&gt;/*Your other processing logic will go here*/&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;color: black; font-family: &#39;Courier New&#39;;&quot;&gt;   &lt;/span&gt;return&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt; Json(&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;new&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: &#39;Courier New&#39;;&quot;&gt;   &lt;/span&gt;{
       nameret=name,
       emailret=email,
       messageret=message
     },&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;JsonRequestBehavior&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;.AllowGet);&lt;/span&gt;&lt;/span&gt;
&lt;span style=&quot;font-family: Consolas;&quot;&gt;&lt;span style=&quot;font-family: Consolas;&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
Let me explain that to you. This controller will take name, email and message from the modal dialog as input and will output a Json result with name, email and message. Here before returning the content you can also save it to database you if want or you can write any other processing logic like you might want to append Mr/Mrs before the name.&lt;br /&gt;
&lt;br /&gt;
After the controller is done now let&#39;s write JQuery code that will call this controller. We need to append this code in the previous script we had defined inside the $(document).ready() function.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;pre style=&quot;background-color: #eeeeee; border: 1px dashed rgb(153, 153, 153); color: black; line-height: 14px; overflow: auto; padding: 5px; width: 100%;&quot;&gt;&lt;code&gt;&lt;span style=&quot;font-family: inherit;&quot;&gt;
//if you see that code in the partial view our submit button
//is defined as .close class, so below code says on document ready
//append click event to this button
$(&quot;.close&quot;).live(&quot;click&quot;, function (e) {
            //prevent default action on the button click
            e.preventDefault();
            //get value of name textbox id=Namecontact
            //put in variable name
            var name = $(&quot;#Namecontact&quot;).val();
            //get value of email textbox id=emailcontact
            //put in variable email
            var email = $(&quot;#emailcontact&quot;).val();
            //get value of message textarea id=messagecontact
            //put it in variable message
            //note since messagecontact is a textarea
            //we need to use .text() rather than .val()
            var message = $(&quot;#messagecontact&quot;).text();
            //Start ajax call
            $.ajax({
            //define method for sending data to controller
                type: &quot;POST&quot;,
                //define controller URL
                url: &quot;/Home/ContactUs&quot;,
                //define data to send to controller
                //if you remember our controller accepts
                //3 parameters name, email and message
                data: { &quot;name&quot;: name, &quot;email&quot;: email, &quot;message&quot;: message },
                //create a success function
                //this method is executed if controller
                //defined by the URL is found
                //and it accepts the data sent
                //control comes to this point if the controller
                //is executed. So data in function(data)
                //contains the Json data we sent
                //from the controller
                success: function (data) {
                    //Now in the div with id result defined in
                    //index page previously we will put in the
                    //data. As you can see Json data is very&amp;nbsp;
                    //easy way of returning to ajax call because
                    //now you can simply say data(dot)variable sent
                   //and you will get the returned value.
                    $(&quot;#result&quot;).html(&quot;&amp;lt;ul&amp;gt;&amp;lt;li&amp;gt;Name: &quot; + data.nameret + &quot;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Email: &quot; + data.emailret+ &quot;&amp;lt;/li&amp;gt;&amp;lt;li&amp;gt;Message: &quot;+data.messageret+&quot;&amp;lt;/li&amp;gt;&amp;lt;/ul&amp;gt;&quot;);
                    //now close the modal dialog we opened
                    $(&quot;.dialog&quot;).dialog(&quot;close&quot;);
                },
                //control comes to this function if ajax doesn&#39;t
               //find the controller or controller doesn&#39;t accepts
               //the data sent or controller throws exception

                error: function (data) {
                    //If it happens alert user of the error
                    alert(&quot;There was error processing this&quot;);
                    //close the modal dialog
                    $(this).closest(&quot;.dialog&quot;).dialog(&quot;close&quot;);
                }
            });

        });&lt;/span&gt;&lt;span style=&quot;font-family: &#39;Andale Mono&#39;, &#39;Lucida Console&#39;, Monaco, fixed, monospace;&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br /&gt;
So this now completes our dialog. Please note that this JQuery needs to be inside $(document).ready() function.&lt;br /&gt;
&lt;br /&gt;
PS: You can also add validations to this the modal form but I have not included it here. You can also send modal from dB to the Views and update those modal from result from the view. For this you will have to make changes to the controller actions defined.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSzh6rDCXDlW4k1C_W2e4nU0z9jBWbFGCTlCydmkvXpnI_zB1WSCrn50BA8nMq0qdrY7ufG7_T38FhXd8poZipc97M07Vqa77z4_1iH09QjKpJdPU49dlk_1lQFFU5NpMTesNgK7qQZALe/s1600/aftercomplete1.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;344&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSzh6rDCXDlW4k1C_W2e4nU0z9jBWbFGCTlCydmkvXpnI_zB1WSCrn50BA8nMq0qdrY7ufG7_T38FhXd8poZipc97M07Vqa77z4_1iH09QjKpJdPU49dlk_1lQFFU5NpMTesNgK7qQZALe/s640/aftercomplete1.JPG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCDB6uFqKal6ATqE9G55VlEBxV7kcy1udFT80Pk26SYgmAxBnivagsJu41_PlmzxudrR6CPFfVtjufJw3mJwJTJ6xdAvbKFIFkyXRdwdQ0ATd97cCccDIZfN0qfCz_au1C8ZSLmNZzMPHu/s1600/aftercomplete2.JPG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;342&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCDB6uFqKal6ATqE9G55VlEBxV7kcy1udFT80Pk26SYgmAxBnivagsJu41_PlmzxudrR6CPFfVtjufJw3mJwJTJ6xdAvbKFIFkyXRdwdQ0ATd97cCccDIZfN0qfCz_au1C8ZSLmNZzMPHu/s640/aftercomplete2.JPG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://amitraya.blogspot.com/feeds/6869374863560340069/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amitraya.blogspot.com/2012/09/modal-dialog-form-view-using-jquery.html#comment-form' title='28 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7510043426665993888/posts/default/6869374863560340069'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7510043426665993888/posts/default/6869374863560340069'/><link rel='alternate' type='text/html' href='http://amitraya.blogspot.com/2012/09/modal-dialog-form-view-using-jquery.html' title='Modal Dialog form view using JQuery ASP.Net MVC'/><author><name>Amit Raya</name><uri>http://www.blogger.com/profile/10060067214284586056</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipvAWOWQ9LPkr7JxLoG8HIOedrwJKpTLwsKznED2Q_hGs7sDHiNsO2FFn2W_wlNZrPU6QFK8-yu68EXbUD2QhQKg3Gq44V8_OCUGT9CEXJM-OUTpNh3m5da0QPZ7A7dJQDsfE4zzjXGIID/s72-c/Create+Project.JPG" height="72" width="72"/><thr:total>28</thr:total></entry><entry><id>tag:blogger.com,1999:blog-7510043426665993888.post-2679265013322376761</id><published>2012-05-04T16:15:00.000+05:30</published><updated>2012-07-13T17:51:05.192+05:30</updated><category scheme="http://www.blogger.com/atom/ns#" term=".NET"/><category scheme="http://www.blogger.com/atom/ns#" term="asp.net"/><category scheme="http://www.blogger.com/atom/ns#" term="ASP.NET MVC"/><category scheme="http://www.blogger.com/atom/ns#" term="dot net"/><category scheme="http://www.blogger.com/atom/ns#" term="Entity"/><category scheme="http://www.blogger.com/atom/ns#" term="Entity framework"/><category scheme="http://www.blogger.com/atom/ns#" term="MVC"/><category scheme="http://www.blogger.com/atom/ns#" term="Razor"/><category scheme="http://www.blogger.com/atom/ns#" term="SQL Express"/><category scheme="http://www.blogger.com/atom/ns#" term="sqlexpress"/><category scheme="http://www.blogger.com/atom/ns#" term="VWD 2010"/><title type='text'>Create Websites using SQL Express with ASP.NET MVC</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
I was trying my hand on 
learning ASP.NET MVC but one thing that create most problem for me was that most of the tutorials 
used SQL Compact (here after reffered as SQL CE). But I wanted to use SQL Express as my database server. I had to 
struggle a lot to find a way to make website using SQL Express and ASP.NET MVC. So I thought if I put it here 
it might help :)&lt;br /&gt;
&lt;br /&gt;
To start with this, we first need to create a solution 
in VWD 2010 with MVC.&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
1. Create a project, 
choose a name for the project, &amp;nbsp;for convenience I have named it &quot;MvcTest&quot;. Click &quot;Ok&quot; 
button.&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZEiNKnnWJndw0oZbNZIxaAnYRe19EFjRiBu-ex3re8XmOg4-_3BhhRTbAE_X4VN7NPuMdef6PuZozMuQHOf6PuHlPwlxi3crg3asMDpPDO5_c2Tg0kFeFgFKZ3nLQHA5wbFxSimoB0mLU/s1600/Capture.PNG&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;440&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZEiNKnnWJndw0oZbNZIxaAnYRe19EFjRiBu-ex3re8XmOg4-_3BhhRTbAE_X4VN7NPuMdef6PuZozMuQHOf6PuHlPwlxi3crg3asMDpPDO5_c2Tg0kFeFgFKZ3nLQHA5wbFxSimoB0mLU/s640/Capture.PNG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2. Choose Internet 
Application and Razor as your view engine and click &quot;Ok&quot;.&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZPBzK1hyIop3D3tCgh8_Vm1GyRL38kNJJ4xVpmNVeNlAFVIpocgzW_CqxNqtBTdnagQw-jQcQW2udn5RfBMq4TVj9Cx7aE5Jmzk2peC3jGlXA_-OweU3L83FfuGdGg3oxkYVgeesz1rnd/s1600/Internet+project.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;578&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZPBzK1hyIop3D3tCgh8_Vm1GyRL38kNJJ4xVpmNVeNlAFVIpocgzW_CqxNqtBTdnagQw-jQcQW2udn5RfBMq4TVj9Cx7aE5Jmzk2peC3jGlXA_-OweU3L83FfuGdGg3oxkYVgeesz1rnd/s640/Internet+project.PNG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
3. You will see that VWD 
creates different files for you automatically.&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_TMTfBmFKWVaF8R5vOQE7Fprew3q-fhBSPt6KwrQEcGAimnOty7SGr8E_9_ax9JdfPQ7xYuMGSKfEqdqv1-hzvOwXSuOZP2c9ku9I_UvuYHlL22mq0eJmOElDI-tZofem_HnVKfBkgkUv/s1600/Explorer.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_TMTfBmFKWVaF8R5vOQE7Fprew3q-fhBSPt6KwrQEcGAimnOty7SGr8E_9_ax9JdfPQ7xYuMGSKfEqdqv1-hzvOwXSuOZP2c9ku9I_UvuYHlL22mq0eJmOElDI-tZofem_HnVKfBkgkUv/s640/Explorer.PNG&quot; width=&quot;275&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
4. Now in the Model folder 
create a Model. You can name it Test.cs&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVrihSLGmyr7vyn1Q56KRRVXRmfZVakLrULs5KczSWa7gr6NIQHL5G1MrFp05xSXsp8kKFD1oYUtAbjbz30tuXmbiOmW260jx-4up9BZk7-f_-2DEqvHMT2qsJK3wcwpC2UOfrApr3WWK1/s1600/modelCreate.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;490&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVrihSLGmyr7vyn1Q56KRRVXRmfZVakLrULs5KczSWa7gr6NIQHL5G1MrFp05xSXsp8kKFD1oYUtAbjbz30tuXmbiOmW260jx-4up9BZk7-f_-2DEqvHMT2qsJK3wcwpC2UOfrApr3WWK1/s640/modelCreate.PNG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
5. In the class that is 
created add the columns you want to specify in the table in the database, for example here I 
have created “{get; set;}” property for four items, ID, Name, RollNumber and 
Fee. When database will be created by Entity framework of ASP.NET MVC these will 
represent the columns in the table that is created. The definition for table 
however is not included in this picture (below), that will be given in further 
steps.&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDLu6ZEzpwZoCyLziZs3W_qyhQt1SZTXALih48Atw25yKV5F-qJoS-Z7xbUdqRI0tT4VhMH3FZYWlkGe0Impa1T5-HW_fcmRDvN914GdIZkNcCDQD7tw5WocRQX8RkQEApjyoQVk-moHFg/s1600/3.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;300&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDLu6ZEzpwZoCyLziZs3W_qyhQt1SZTXALih48Atw25yKV5F-qJoS-Z7xbUdqRI0tT4VhMH3FZYWlkGe0Impa1T5-HW_fcmRDvN914GdIZkNcCDQD7tw5WocRQX8RkQEApjyoQVk-moHFg/s400/3.PNG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
6. Now create a context class. 
Name the same as TestContext. This context class will basically define the 
database and table for your application. For adding context class you need to 
refer to System.Data.Entity. After adding the context your class will basically 
look like below, here Tests represents your database and Test (given in DbSet&amp;lt;Test&amp;gt;) represents your table.&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXlHjDl1oFaSjRt-fTtdVs7Xzz-8d6ukaNBvzS0Y4i_nozXuPWWo2TozbsfjNufXPnjTzQFzLamc0LRGZmy1vfkhSnZUWU7q5HNUzI2OYZrfi86tYrPqDFr1ZWkTwLYFEpojvcQbqRVoaV/s1600/4.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;302&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXlHjDl1oFaSjRt-fTtdVs7Xzz-8d6ukaNBvzS0Y4i_nozXuPWWo2TozbsfjNufXPnjTzQFzLamc0LRGZmy1vfkhSnZUWU7q5HNUzI2OYZrfi86tYrPqDFr1ZWkTwLYFEpojvcQbqRVoaV/s400/4.PNG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
7.  Now coming to the point 
where you add connection string to the webconfig file. &lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
The connection string to 
use SQL CE is:&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;border-bottom-style: dashed; border-left-style: dashed; border-right-style: dashed; border-size: 1px; border-top-style: dashed; text-align: center;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&amp;lt;add connectionstring=&quot;Data 
Source=|DataDirectory|Test.sdf&quot; name=&quot;TestContext&quot; 
providername=&quot;System.Data.SqlServerCe.4.0&quot;/&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #333333; font-family: arial, helvetica, clean, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;Courtesy&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: arial, helvetica, clean, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt; &lt;/span&gt;: 
&lt;a href=&quot;http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application&quot;&gt;http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application&lt;/a&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
We add this connection 
string to web.config file on the root of the solution.&lt;br /&gt;
&lt;br /&gt;
To change the 
connection string to use SQLExpress we can use the following 
string:&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;border-bottom-style: dashed; border-left-style: dashed; border-right-style: dashed; border-size: 1px; border-top-style: dashed; text-align: center;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
&amp;lt;add name=&quot;TestContext&quot; 
connectionString=&quot;Server=.\SQLExpress;Database=Test;Integrated 
Security=SSPI;User Instance=true&quot; providerName=&quot;System.Data.SqlClient&quot; /&amp;gt; 
&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #333333; font-family: arial, helvetica, clean, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;background-color: white; color: #333333; font-family: arial, helvetica, clean, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt;Courtesy&lt;/span&gt;&lt;span style=&quot;background-color: white; color: #333333; font-family: arial, helvetica, clean, sans-serif; font-size: 13px; line-height: 16px;&quot;&gt; 
: &lt;a href=&quot;https://www.google.com/search?sourceid=chrome&amp;amp;ie=UTF-8&amp;amp;q=using+sql+express+with+asp.net+mvc&quot; target=&quot;_blank&quot;&gt;Lot of google searches and some personal tweaks&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
Now once the connection 
string is defined in web.config file, &lt;strong&gt;we need to build the solution 
&lt;/strong&gt;before we proceed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
8. Once you have built the 
solution in the controller folder try to add Test controller with the following 
parameters&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
a. Template: Controller with 
read/write actions and views, using Entity Framework&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
b. Model class: 
Test(MvcTest.Models)&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
c. Data context class: 
TestContext(MvcTest.Models)&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
d. Views: Razor (CSHTML)&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdUrGhZuBkFHBf86_XfmcIkgcNNQ-PS8mJKTaCaaucb0gMQ0W-2mTLG2lkyyf2Hlv16ZlfC9yYBbMNp_43uRof9DzlflPdENjwcgeTpbwFDp1lQPBiChUhQnEyBUu7PRd-7DAeNRpZnM8w/s1600/5.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;260&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdUrGhZuBkFHBf86_XfmcIkgcNNQ-PS8mJKTaCaaucb0gMQ0W-2mTLG2lkyyf2Hlv16ZlfC9yYBbMNp_43uRof9DzlflPdENjwcgeTpbwFDp1lQPBiChUhQnEyBUu7PRd-7DAeNRpZnM8w/s400/5.PNG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
9. Sometimes you will get an 
error saying “Unable to create dbo.Test”, if this happens I suggest adding 
Tests.mdf database manually to App_Data folder, you can do that by right 
clicking on the App_Data folder Add=&amp;gt;New Item=&amp;gt; SQL Server Database as 
given below:&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSgP1IhdqRyVwIsdDLZ_GLIe2XDOBoh1AQb4NEmBU3ankuZPioajP8K3aDPoG_zlYKPOCul09JPZVXBfgcv20iRQu8WMcOPky-qtqp_xXXfePOyAvA9-SpXfsiy_tdJFgsvXEWmlK0QpUI/s1600/7.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;443&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSgP1IhdqRyVwIsdDLZ_GLIe2XDOBoh1AQb4NEmBU3ankuZPioajP8K3aDPoG_zlYKPOCul09JPZVXBfgcv20iRQu8WMcOPky-qtqp_xXXfePOyAvA9-SpXfsiy_tdJFgsvXEWmlK0QpUI/s640/7.PNG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
10. Click on the add button. 
Now you will see magic happen. VWD will automatically create Index.cshtml, 
Details.cshtml, Create.cshtml, Edit.cshtml, Delete.cshtml files for you in your 
view directory.&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHUEzYdkPULovBs4MbVypFLhRt4uGr2YQu5PMtEGhQSqNSLH43P7TVm65VmIKYUI-Q2OcAV6kxiypg9WLn098f3yT868LYExjQwxv8deQO2am35uRd31e66wzCdOmI2DTcaianZrcSCk3_/s1600/6.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;366&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiHUEzYdkPULovBs4MbVypFLhRt4uGr2YQu5PMtEGhQSqNSLH43P7TVm65VmIKYUI-Q2OcAV6kxiypg9WLn098f3yT868LYExjQwxv8deQO2am35uRd31e66wzCdOmI2DTcaianZrcSCk3_/s400/6.PNG&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
11. Now you are free to use 
and tweak the application to your liking. As of now with this much code only you 
already have working application. Screen Shots for Index page, Create page, Edit 
page and Delete page is given below. To get to the Index page run the 
application from VWD using Ctrl+F5. In the address bar of Internet Explorer 
append “Test” to the address. eg. http://localhost:xxxx/Test&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
a. Index&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGv8UVg8Q1gfipAVS_gX3EIQqZ4SicnOnO_pXVcmu9rfg5KYtIPVpDb_Sb3lgoEpK1zXh-P3iQg5V7VdO4yyh7tK8v6b0CtSzFVkgYSwggJjG1fMQVMIbJCG6NqqZawv8bAIXoHBXK6oT9/s1600/9.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;556&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGv8UVg8Q1gfipAVS_gX3EIQqZ4SicnOnO_pXVcmu9rfg5KYtIPVpDb_Sb3lgoEpK1zXh-P3iQg5V7VdO4yyh7tK8v6b0CtSzFVkgYSwggJjG1fMQVMIbJCG6NqqZawv8bAIXoHBXK6oT9/s640/9.PNG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
b. Create (Click on Create New Hyperlink to get to this 
page) &lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgar8_R_TVFZiuqtweIinVyXU3MMu2XhPUhoMHyd5qUxJGhAdWC4kbxRcc6fp2pJnGsAH4v8ZbIROtsYrOKUodrZZvQaB6dJeGU05qr-bFFYsI3E9oQftz1XBH2otpRh1HhNeexHEx2WEQ4/s1600/8.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;558&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgar8_R_TVFZiuqtweIinVyXU3MMu2XhPUhoMHyd5qUxJGhAdWC4kbxRcc6fp2pJnGsAH4v8ZbIROtsYrOKUodrZZvQaB6dJeGU05qr-bFFYsI3E9oQftz1XBH2otpRh1HhNeexHEx2WEQ4/s640/8.PNG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
c. Changed Index page. Once the data is created you are 
redirected back to Index.&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipnQM5uFazSvhxsrQOri1eheqJts55hy4YGaVtz9UEtuALOw_4VKctymd2lEJM45h5xgcpuCpHrMVkfc-vmTfH5Zkh7lSuxvyPBO6TnDC55qCAwFxuZZL1ao_UCp0Flo69XJ-PgH-q42bg/s1600/10.PNG&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;560&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipnQM5uFazSvhxsrQOri1eheqJts55hy4YGaVtz9UEtuALOw_4VKctymd2lEJM45h5xgcpuCpHrMVkfc-vmTfH5Zkh7lSuxvyPBO6TnDC55qCAwFxuZZL1ao_UCp0Flo69XJ-PgH-q42bg/s640/10.PNG&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
d. Click on Edit, Details and Delete for viewing respective pages. 
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
Hope this post helps you to 
use SQLExpress with ASP.NET MVC :)&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;strong&gt;&lt;br /&gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;strong&gt;PS:&lt;/strong&gt; I have just started learning ASP.NET MVC, so I might have made some mistakes (which 
doesn’t look likely because the application is working but still) please help me 
to correct them.&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div dir=&quot;ltr&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;color: red;&quot;&gt;Disclaimer:&lt;/span&gt; &lt;em&gt;I am not the creator of ASP.NET, MVC, Razor 
or Entity, all I am trying to do is put up a simple tutorial in place using SQL 
Express and ASP.NET MVC and all my learning is from the resources collected from 
the internet.&lt;/em&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://amitraya.blogspot.com/feeds/2679265013322376761/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://amitraya.blogspot.com/2012/05/create-websites-using-sql-express-with.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/7510043426665993888/posts/default/2679265013322376761'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/7510043426665993888/posts/default/2679265013322376761'/><link rel='alternate' type='text/html' href='http://amitraya.blogspot.com/2012/05/create-websites-using-sql-express-with.html' title='Create Websites using SQL Express with ASP.NET MVC'/><author><name>Amit Raya</name><uri>http://www.blogger.com/profile/10060067214284586056</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZEiNKnnWJndw0oZbNZIxaAnYRe19EFjRiBu-ex3re8XmOg4-_3BhhRTbAE_X4VN7NPuMdef6PuZozMuQHOf6PuHlPwlxi3crg3asMDpPDO5_c2Tg0kFeFgFKZ3nLQHA5wbFxSimoB0mLU/s72-c/Capture.PNG" height="72" width="72"/><thr:total>3</thr:total></entry></feed>