<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress.com" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>mvc3 &amp;laquo; WordPress.com Tag Feed</title>
	<link>http://en.wordpress.com/tag/mvc3/</link>
	<description>Feed of posts on WordPress.com tagged "mvc3"</description>
	<pubDate>Thu, 23 May 2013 08:08:00 +0000</pubDate>

	<generator>http://en.wordpress.com/tags/</generator>
	<language>en</language>

<item>
<title><![CDATA[Advanced Model Binding in MVC3]]></title>
<link>http://himynameisriz.wordpress.com/2012/08/22/advanced-model-binding-mvc3/</link>
<pubDate>Wed, 22 Aug 2012 16:24:24 +0000</pubDate>
<dc:creator>himynameisriz</dc:creator>
<guid>http://himynameisriz.wordpress.com/2012/08/22/advanced-model-binding-mvc3/</guid>
<description><![CDATA[While at work, I had come across a very challenging model binding situation. My situation was, I had]]></description>
<content:encoded><![CDATA[<p>While at work, I had come across a very challenging model binding situation. My situation was, I had a <strong><span style="color:#3366ff;">Model.</span> </strong>This Model has some pretty basic values, an ID, a Name, etc. Also within this Model, you are allowed to have children of the same Model. Basically represented, this Model could have a List of Model.</p>
<pre class="brush: csharp; title: ; notranslate" title="">List&#60;Model&#62; ChildModel { get; set; }s</pre>
<p>And as you can see, each of those children can have children. Let&#8217;s get to the code.</p>
<p>I have a model, and this model holds some pretty basic values:</p>
<pre class="brush: csharp; title: ; notranslate" title="">
public class Model
 {
 public Model()
 {
 ChildModels = new List&#60;Model&#62;();
 }

public int ModelId { get; set; }

public string ModelName { get; set; }

public string ModelImagePath { get; set; }

public bool ToAssign { get; set; }

public IModel ParentModel { get; set; }

public List&#60;Model&#62; ChildModels { get; set; }
 }
</pre>
<p>Now, as you can see, there is a hierarchy achieved with this model. A certain model stored from the database into an <strong><span style="color:#3366ff;">IModel</span></strong> has the possibility to have children <strong><span style="color:#3366ff;">IModels.</span></strong><span style="color:#3366ff;"> </span>While this wouldn&#8217;t be too hard to handle itself, with something along the lines of:<strong><br />
</strong></p>
<pre class="brush: csharp; title: ; notranslate" title="">
@for (int i = 0; i &#62; Model.ChildModels.Count; i++)
{
     @Html.CheckBoxFor(m =&#62; m.ChildModels[i])
     @Html.HiddenFor(m =&#62; m.ChildModels[i])
}
</pre>
<p>it becomes more complicated because of the hierarchy. The children can have its own children, creating an issue when trying to make a recursive call to a partial view:</p>
<pre class="brush: csharp; title: ; notranslate" title="">
@for (int i = 0; i &#62; Model.ChildModels.Count; i++)
{
     @Html.CheckBoxFor(m =&#62; m.ChildModels[i])
     @Html.HiddenFor(m =&#62; m.ChildModels[i])
     if (m.ChildModels[i].ChildModels.Count &#62; 0)
     {
          @Html.Partial(&#34;partialView&#34;, Model.ChildModels[i].ChildModels)
     }
}
</pre>
<p>The problem with this recursive call is that each grand-child&#8217;s attempted value storage when persisting to the controller would be</p>
<pre class="brush: csharp; title: ; notranslate" title="">Model.ChildCompanies[i]</pre>
<p>As you can tell, this is going to have problems with previously set child companies from the first parent. After many hours of attempts, different techniques (Lists inside the Model with a generic name [Ids/ToAssign], javascript/jquery parsing, etc), my teammate and I had found something that finally had worked.</p>
<p>ViewDataDictionary <a title="ViewDataDictionary" href="http://msdn.microsoft.com/en-us/library/system.web.mvc.viewdatadictionary(v=vs.98).aspx" target="_blank">http://msdn.microsoft.com/en-us/library/system.web.mvc.viewdatadictionary(v=vs.98).aspx</a></p>
<p>Thanks to this post: <a href="http://forums.asp.net/post/4309562.aspx">http://forums.asp.net/post/4309562.aspx</a> we were able to finally do some advanced model binding. The set up is actually quite simple:</p>
<p>First, you create your <strong><span style="color:#3366ff;">ViewDataDictionary</span> </strong>with the type of the <strong><span style="color:#3366ff;">Model</span> </strong>and the original <strong><span style="color:#3366ff;">Model.</span></strong> Then you set a prefix for each of the HtmlHelpers to add into your mark up:</p>
<pre class="brush: csharp; title: ; notranslate" title="">
//this goes in your cshtml
var dataDictionary = new ViewDataDictionary&#60;Location.Model&#62;(Model);

dataDictionary.TemplateInfo.HtmlFieldPrefix = Html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(&#34;Model&#34;);
</pre>
<p>So, when you create a HtmlHelper, such as:</p>
<pre class="brush: csharp; title: ; notranslate" title="">@Html.CheckBoxFor(m =&#62; m.ToAssign)

</pre>
<p>It would be forced to have the prefix &#8220;Model,&#8221; or whatever you put in there.</p>
<p>Next, when calling your recursive partial view, you add that into the parameters as a <strong><span style="color:#3366ff;">ViewDataDictionary</span></strong>:</p>
<pre class="brush: xml; title: ; notranslate" title="">
&#60;ul id=&#34;treeview&#34;&#62;
     @Html.Partial(&#34;modelTreeNode&#34;, Model, dataDictionary)
&#60;/ul&#62;
</pre>
<p>I&#8217;m using an unordered list to allow for a jquery treeview (hence the id set as treeview) for a more hierarchy look. Now, as you can see, the partial view &#8220;modelTreeNode&#8221; will be set for each object to have the prefix &#8220;Model.&#8221; This ensures that each of the parent&#8217;s children is being bound correctly when attempting to persist the objects. Now, for the partial view itself:</p>
<pre class="brush: csharp; title: ; notranslate" title="">&#60;/pre&#62;
@model Location.Model
&#60;li class=&#34;@Model.Id&#34;&#62;
 @Html.CheckBoxFor(m =&#62; m.ToAssign)
 @Html.HiddenFor(m =&#62; m.Id)
 @Model.ModelName //just a display

@if (Model.ChildCompanies.Count &#62; 0)
 {
 &#60;ul&#62;
 @for (int i = 0; i &#60; Model.ChildModels.Count; i++)
 {
 //build the view data
 var dataDictionary = new ViewDataDictionary&#60;Location.Model&#62;(Model);
 dataDictionary.TemplateInfo.HtmlFieldPrefix = Html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(&#34;ChildModels[&#34; + i + &#34;]&#34;);

 &#60;div class=&#34;parent-@Model.Id&#34;&#62;
 &#60;ul&#62;
 @Html.Partial(&#34;modelTreeNode&#34;, Model.ChildModels[i], dataDictionary)
 &#60;/ul&#62;
 &#60;/div&#62;
 }
 &#60;/ul&#62;
 }
&#60;/li&#62;
&#60;pre&#62;
</pre>
<p>Now, let me break it down. First, you add a new unordered list within the same list item (for treeview once again), and throw in your <strong>CheckBoxFor</strong> and <strong>HiddenFor</strong> for persisting the data.</p>
<p>Now, when you find that you parent has atleast one child, you start off again by creating a <strong><span style="color:#3366ff;">ViewDataDictionary,</span> </strong>and creating a new prefix of &#8220;<strong>ChildModels[i].&#8221; </strong>This means when you now use <strong>CheckBoxFor</strong> or <strong>HiddenFor, </strong>they are going to have the prefix added to the beginning of each HtmlHelper, since you are adding this <strong><span style="color:#3366ff;">ViewDataDictionary </span></strong>into your partial view call.</p>
<p>But wait, what&#8217;s this? You already have a <strong><span style="color:#3366ff;">ViewDataDictionary</span> </strong>set for your partial view, and now you&#8217;re just rendering it again. Should that cause a problem? Well, if it wasn&#8217;t for the hierarchy, it would. See, you already have a <strong><span style="color:#3366ff;">ViewDataDictionary</span> </strong>setting a prefix of &#8220;Model.&#8221; Now, you have two prefixes being added to each <strong>HtmlHelper.</strong> First, you have the new one being added, the most recent one, so your HtmlHelper might look like <strong>ChildModels[i].ChildModels[j].ToAssign</strong>, and so on. But since you originally set the <strong><span style="color:#3366ff;">ViewDataDictionary</span> </strong>to add the prefix &#8220;Model.&#8221; So when being rendered, it turns out to be <strong>Model.ChildModels[i].ChildModels[j].ToAssign! </strong></p>
<p>And that&#8217;s exactly what we&#8217;re looking for, for advanced model binding. This means as many children, can have children, and those can have children, and etc. Each new grandchild would have a new prefix added. This allows for hierarchy at many deep levels.</p>
<p>Finally, your controller action should look something like this:</p>
<pre class="brush: csharp; title: ; notranslate" title="">
public ActionResult AssignImageTo(Model viewModel)
{
//your code here
}
</pre>
<p>Your parent company, if it has children, will persist, and the children of those children will persist, and so on.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Weekly Favs - Games, Art, and Music]]></title>
<link>http://dungeontalk.com/2012/08/20/weekly-favs-games-art-music/</link>
<pubDate>Tue, 21 Aug 2012 03:05:08 +0000</pubDate>
<dc:creator>Dungeon Talk</dc:creator>
<guid>http://dungeontalk.com/2012/08/20/weekly-favs-games-art-music/</guid>
<description><![CDATA[Sorry for the delay but now on to Weekly Favs Number #3: Starting out with number 3, which is a TIE!]]></description>
<content:encoded><![CDATA[Sorry for the delay but now on to Weekly Favs Number #3: Starting out with number 3, which is a TIE!]]></content:encoded>
</item>
<item>
<title><![CDATA[Sr. C#/.Net Application Architect/Lead (Full-Time) - Manhattan, NYC - $125K - $140K Base Salary]]></title>
<link>http://itmediajobsnyc.wordpress.com/?p=941</link>
<pubDate>Tue, 14 Aug 2012 16:05:56 +0000</pubDate>
<dc:creator>itmediajobsnyc</dc:creator>
<guid>http://itmediajobsnyc.wordpress.com/?p=941</guid>
<description><![CDATA[Sr. C#/.Net Application Architect/Lead LOCATION: Manhattan, NYC TERMS: Full-Time INDUSTRY: Digital M]]></description>
<content:encoded><![CDATA[Sr. C#/.Net Application Architect/Lead LOCATION: Manhattan, NYC TERMS: Full-Time INDUSTRY: Digital M]]></content:encoded>
</item>
<item>
<title><![CDATA[Razor view engine with MVC3 in ASP.NET]]></title>
<link>http://mscoderepository.wordpress.com/2012/08/12/razor-view-engine-with-mvc3-in-asp-net/</link>
<pubDate>Sun, 12 Aug 2012 04:38:46 +0000</pubDate>
<dc:creator>pubudugayan</dc:creator>
<guid>http://mscoderepository.wordpress.com/2012/08/12/razor-view-engine-with-mvc3-in-asp-net/</guid>
<description><![CDATA[With the MVC 3, Microsoft Cooperation has introduced a new view engine called “Razor”. In this artic]]></description>
<content:encoded><![CDATA[<p>With the MVC 3, Microsoft Cooperation has introduced a new view engine called “Razor”. In this article I will explain how the Razor looks like with the aspx view engine.  Before I gained the knowledge about the Razor view engine, I have misunderstood it as a kind of new language; however it is not like that. In simple words Razor is a tool that we can use in ASP.NET MVC.</p>
<div>Other than the Razor there are few view engines available with aspx, such as Spark, NHaml. But in this article I will discuss only about the Razor engine.  In visual studio 2010, it gives as much as flexibility to use the any view engine in MVC pattern. For an example if we need to use ASPX with cshtml  or vbhtml , it is possible to use both together in one project.  See the below picture</div>
<div></div>
<div><img src="http://mscoderepository.files.wordpress.com/2012/08/solutionscreen.png?w=212" alt="" /></div>
<div></div>
<div><strong>Adding Razor view model to the Project</strong></div>
<div></div>
<div>There are two ways that you can add Razor view model to a project. As we all are familiar, the most famous way is to Right click on the views folder -&#62; Add- &#62; New Item &#8211; &#62; MVC 3 View page with Layout (Razor).  See the following screen</div>
<div><img src="http://mscoderepository.files.wordpress.com/2012/08/add_item_screen.png?w=300" alt="" /></div>
<div></div>
<div>Second method is add view screen. See the following picture</div>
<div><img src="http://mscoderepository.files.wordpress.com/2012/08/add_view.png?w=300" alt="" /></div>
<div></div>
<div>In a typical aspx view engine we need to use five characters (&#60;%=  %&#62;) to add server side functions in the html page, but thanks to the Razor now we have to use only one character (@). In addition like aspx we do not need to close the code block in razor engine.</div>
<div></div>
<div>
<div>In the following example I showed a sample code. In that code my view model is based on the Product model.</div>
<div></div>
<div></div>
<div>@model MvcApplication.Models.Product</p>
<div></div>
<div>@{</div>
<div>    ViewBag.Title = &#8221;Product&#8221;;</div>
<div>}</div>
<div></div>
<div>&#60;h2&#62;Name : @Model.Name &#60;/h2&#62;</div>
<div></div>
<div>@if (Model.Category == &#8221;Phone&#8221;)</div>
<div>{</div>
<div></div>
<div>        &#60;p&#62;@Model.Category &#60;b&#62;is awesome!&#60;/b&#62; &#60;/p&#62;</div>
<div></div>
<div>     }</div>
<div></div>
<div>Time view : @DateTime.Now.ToShortTimeString()</div>
<div></div>
<div>As you can see the first line; <strong>@model </strong>chunk uses the product model in the project.  This type of view model is called as strong typed views. Moreover by using <strong>@Model</strong> we can access properties, fields, methods that belong to the related model (in my case it is a Product).</p>
<div>If you critically go through the code you might find a tiny difference in the code. Yeap you are correct…. In the very first line @model ‘s m is simple but in the other @Model ‘s M is capital. The reason is @model tells which model it refers for the view and @Model is used to refer the objects that contain the model object as I mentioned above.  When you run the code it will show the following result.</div>
<div></div>
<div><img src="http://mscoderepository.files.wordpress.com/2012/08/exmple1result.png?w=300" alt="" /></div>
<div>Furthermore, in the above example I have inserted an  if condition. Not only the if condition we can use any type of C # or vb.net code within the Razor view engine and the Razor engine is intelligent enough to identify the executable codes from the html tags.</div>
<div></div>
<div>
<div>Other most important thing is Visual Studio is fully support the Razor view engine. When you type<strong>@Model. </strong>On your cshtml file visual studio popped up all the methods and properties that belongs to the model object.  Following screen shot shows you how it works.</div>
<div></div>
<div><img src="http://mscoderepository.files.wordpress.com/2012/08/exmple3result.png?w=300" alt="" /></div>
<div><strong>Little bit complex..</strong></div>
<div>In case if we need to use the nested @Models how we can use? The following sample code shows how we can handle that kind of thing.</div>
<div>
<p>&#60;h2&#62;Name : @Model.Name &#60;/h2&#62;</p>
<p>@if (Model.Category == &#8221;Phone&#8221;)</p>
<p>{</p>
<p>&#60;p&#62;@Model.Category &#60;b&#62;is awesome!&#60;/b&#62; &#60;/p&#62;</p>
<p>&#60;pre&#62;</p>
<p>With the largest screen of any Windows Phone,</p>
<p>the HTC TITAN lets you work big and play big.</p>
<p>Sporting a 4.7” screen and an ultra-slim 9.9mm unibody contoured design,</p>
<p>the HTC TITAN is unlike anything you’ve ever held.</p>
<p>Time view : @DateTime.Now.ToShortTimeString()</p>
<p>&#60;/pre&#62;</p>
<p>}</p>
</div>
<div><img src="http://mscoderepository.files.wordpress.com/2012/08/exmple2result.png?w=300" alt="" /></div>
<div></div>
<div><strong>View Bag feature</strong></p>
<div>View bag feature is not that much different from the view data method and it is a dynamic type. Following example code show how to use the view bag method.</div>
<div></div>
<div></div>
<div>namespace MvcApplication.Controllers</p>
<div>{</div>
<div>    public class ProductController : Controller</div>
<div>    {</div>
<div>        //</div>
<div>        // GET: /Product/</div>
<div></div>
<div>        public ActionResult Index()</div>
<div>        {</div>
<div></div>
<div>            Product myProduct = new Product</div>
<div>            {</div>
<div>                ProductID =1,</div>
<div>                Name = &#8221;HTC Titan &#8220;,</div>
<div>                Description =&#8221;Mobile Phone&#8221;,</div>
<div>                Category =&#8221;Phone&#8221;,</div>
<div>                Price=234M</div>
<div>             };</div>
<div></div>
<div>            ViewBag.PhoneLocation = &#8221;Hong Kong&#8221;;// you can assign a dynamic value</div>
<div>        }</div>
<div></div>
<div>    }</div>
<div>}</div>
<div></div>
<div>
<p><strong>Cshtml file</strong></p>
<p>@model MvcApplication.Models.Product</p>
<div></div>
<div>@{</div>
<div>    ViewBag.Title = &#8221;Product&#8221;;</div>
<div>}</div>
<div></div>
<div>&#60;h2&#62;Name : @Model.Name &#60;/h2&#62;</div>
<div></div>
<div>@if (Model.Category == &#8221;Phone&#8221;)</div>
<div>{</div>
<div></div>
<div></div>
<div>     &#60;p&#62;@Model.Category &#60;b&#62;is awesome!&#60;/b&#62; &#60;/p&#62;</div>
<div></div>
<div>}</div>
<div></div>
<div>  Phone located in: @ViewBag.PhoneLocation</div>
<div>  Timeview : @DateTime.Now.ToShortTimeString()</div>
<div></div>
<div><strong><em>Important: </em></strong>If we name our cshtml or the vbhtml file that start with “_” then those files  cannot be requested by a user.</div>
<div></div>
<div>Well that’s all for this article and I will prepare a more detailed article regarding the Razor and the MVC3 pattern in future.  In the beginning it is little bit confusing but believe me you will get stick with Razor after few days when you start following up the Razor, the reason is Razor view engine is really flexible and quite simple. Therefore time to say good bye and hope this article will help you to get an entry level idea about the Razor.</div>
<div></div>
<div>
<div>Please add your comments and it will help to improve my blog in future.</div>
<div></div>
<div><strong>Reference</strong></div>
<div> Adam Freeman  &#38; Steven Sanderson (2011). Pro ASP.NET MVC 3 Framework, Third Edition.</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
]]></content:encoded>
</item>
<item>
<title><![CDATA[AGE Knives confirmed for Mash Up! this weekend]]></title>
<link>http://pressthepausebutton.wordpress.com/2012/08/07/age-knives-confirmed-for-mash-up-this-weekend/</link>
<pubDate>Tue, 07 Aug 2012 20:16:39 +0000</pubDate>
<dc:creator>pressthepausebutton</dc:creator>
<guid>http://pressthepausebutton.wordpress.com/2012/08/07/age-knives-confirmed-for-mash-up-this-weekend/</guid>
<description><![CDATA[The incoming Mash Up! event held by Button Masherz confirmed on Sunday another special guest for the]]></description>
<content:encoded><![CDATA[<p>The incoming Mash Up! event held by <strong>Button Masherz</strong> confirmed on Sunday another special guest for the event: Knives.</p>
<p style="text-align:center;"><a href="http://pressthepausebutton.files.wordpress.com/2012/08/marvel-vs-capcom3-screens-2.jpeg"><img class="aligncenter  wp-image-2249" title="marvel-vs-capcom3-screens-2" src="http://pressthepausebutton.files.wordpress.com/2012/08/marvel-vs-capcom3-screens-2.jpeg?w=480&#038;h=280" alt="" width="480" height="280" /></a></p>
<p>Knives (Ray Ruballos) is a relatively new face among Marvel vs. Capcom 3 competitors and will be appearing alongside Infrit and Fanatiq at the event this Saturday. <!--more--></p>
<p>The competition will feature <strong>Super Street Fighter IV: Arcade Edition (2012 ver.)</strong>, <strong>Ultimate Marvel vs. Capcom 3</strong>, and <strong>King of Fighters XIII</strong> with various prize pots ranging from $175-$300.</p>
<p>The event is set to open to attendees at 2 p.m. at the Phoenix Center for the Arts in downtown Phoenix. <del>Those who intend to spectate and casual play only will have to pay $15 for entry, while those who want in on any of the three tournaments are required to pay a $30 entry fee.</del></p>
<p><span style="color:#ff0000;"><strong>UPDATE:</strong></span> T<strong>he Mash Up! hosts confirmed today that the initial $15 spectator fee that was announced earlier was wrong due to a misunderstanding with the venue. The $30 charge applies to all attendees regardless if they are competing or not.</strong></p>
<p>Tons of local groups and faces will be present at the event including AZHP Gaming, Euphoria Gaming, Team Hazmat and many more. For more information, check out the <strong>Button Masherz</strong> official <span style="color:#0000ff;"><a title="Mash Up!" href="http://www.facebook.com/events/137807639690313/" target="_blank"><span style="color:#0000ff;">Facebook event page</span></a></span>.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[LINQ: Sequence Contains No Elements:First()]]></title>
<link>http://chikkanti.wordpress.com/2012/08/02/linq-sequence-contains-no-elementsfirst/</link>
<pubDate>Thu, 02 Aug 2012 05:09:59 +0000</pubDate>
<dc:creator>chikkanti</dc:creator>
<guid>http://chikkanti.wordpress.com/2012/08/02/linq-sequence-contains-no-elementsfirst/</guid>
<description><![CDATA[LINQ: Sequence Contains No Elements: The InvalidOperationException:Sequence contains no lelments exc]]></description>
<content:encoded><![CDATA[LINQ: Sequence Contains No Elements: The InvalidOperationException:Sequence contains no lelments exc]]></content:encoded>
</item>
<item>
<title><![CDATA[Telerik's HTML5 Kendo UI Web Validator Framework]]></title>
<link>http://blog.longle.net/2012/08/02/teleriks-html5-kendo-ui-web-validator-framework/</link>
<pubDate>Thu, 02 Aug 2012 00:34:47 +0000</pubDate>
<dc:creator>Le</dc:creator>
<guid>http://blog.longle.net/2012/08/02/teleriks-html5-kendo-ui-web-validator-framework/</guid>
<description><![CDATA[I recently wrote a blog on Telerik&#8217;s Kendo UI Web MVVM Framework. This blog post was intended]]></description>
<content:encoded><![CDATA[<p>I recently wrote a <a href="http://blog.longle.net/2012/07/28/teleriks-kendo-ui-web-mvvm-framework-rocks/" title="http://blog.longle.net/2012/07/28/teleriks-kendo-ui-web-mvvm-framework-rocks/" target="_blank">blog</a> on <a href="http://docs.kendoui.com/api/framework/kendo" target="_blank">Telerik&#8217;s Kendo UI Web MVVM Framework</a>. This blog post was intended to illustrate the power of MVVM binding on the client side (declaritive binding).</p>
<p>In this blog post I wanted to demonstrate the ability to do some nice validation with the <a href="http://docs.kendoui.com/api/framework/validator" target="_blank">Kendo UI Web Validator Framework</a> which also let&#8217; you do a quite bit of validtion declaritively. With that beind said let&#8217;s get right into it using the MVVM form we created from the previous <a href="http://blog.longle.net/2012/07/28/teleriks-kendo-ui-web-mvvm-framework-rocks/" title="http://blog.longle.net/2012/07/28/teleriks-kendo-ui-web-mvvm-framework-rocks/" target="_blank">post</a>.</p>
<p>Let&#8217;s take a quick at where we left off at on our last form.</p>
<pre class="brush: xml; title: ; notranslate" title="">

    &#60;div id=&#34;formContainer&#34;&#62;
        &#60;h1&#62;
            My First MVVM Web View!&#60;/h1&#62;
        &#60;form id=&#34;myForm&#34; action=&#34;&#34;&#62;
        &#60;label&#62;
            First Name&#60;/label&#62;
        &#60;input type=&#34;text&#34; data-bind=&#34;value: firstName, disabled:  isDisabled&#34; /&#62;
        &#60;label&#62;
            Last Name&#60;/label&#62;
        &#60;input type=&#34;text&#34; data-bind=&#34;value: lastName, disabled:  isDisabled&#34; /&#62;
        &#60;label&#62;
            Email&#60;/label&#62;
        &#60;input type=&#34;text&#34; data-bind=&#34;value: email, disabled:  isDisabled&#34; /&#62;
        &#60;label&#62;
            Twitter&#60;/label&#62;
        &#60;input type=&#34;text&#34; data-bind=&#34;value: twitter, disabled:  isDisabled&#34; /&#62;
        &#60;label&#62;
            Site&#60;/label&#62;
        &#60;input type=&#34;text&#34; data-bind=&#34;value: site, disabled:  isDisabled&#34; /&#62;
        &#60;label&#62;
            Address&#60;/label&#62;
        &#60;input type=&#34;text&#34; data-bind=&#34;value: address, disabled:  isDisabled&#34; /&#62;
        &#60;label&#62;
            City&#60;/label&#62;
        &#60;input type=&#34;text&#34; data-bind=&#34;value: city, disabled:  isDisabled&#34; /&#62;
        &#60;label&#62;
            State&#60;/label&#62;
        &#60;input type=&#34;text&#34; data-bind=&#34;value: state, disabled:  isDisabled&#34; /&#62;
        &#60;label&#62;
            Zip&#60;/label&#62;
        &#60;input type=&#34;text&#34; data-bind=&#34;value: zip, disabled:  isDisabled&#34; /&#62;
        &#60;label&#62;
            Occupation&#60;/label&#62;
        &#60;select data-bind=&#34;source: occupations, value: occupation, disabled:  isDisabled&#34;&#62;
        &#60;/select&#62;
        &#60;br /&#62;
        &#60;br /&#62;
        &#60;input type=&#34;button&#34; value=&#34;Load&#34; data-bind=&#34;click: load&#34; /&#62;
        &#60;input type=&#34;button&#34; value=&#34;Edit&#34; data-bind=&#34;click: edit&#34; /&#62;
        &#60;input type=&#34;button&#34; value=&#34;Cancel&#34; data-bind=&#34;click: cancel&#34; /&#62;
        &#60;input type=&#34;button&#34; value=&#34;Reset&#34; data-bind=&#34;click: reset&#34; /&#62;
        &#60;/form&#62;
    &#60;/div&#62;

</pre>
<p>Now let&#8217;s add a couple of extra fields and declaritively add some validation to our form. While doing this let&#8217;s go ahead and change the types to our input controls with the appropriate HTML5 (<a href="http://www.w3schools.com/html5/html5_form_attributes.asp" title="http://www.w3schools.com/html5/html5_form_attributes.asp" target="_blank">http://www.w3schools.com/html5/html5_form_attributes.asp</a>) types e.g. date, number, email, etc.. <strong><i>Quick note, notice that we are using the HTML5 [pattern] attribute for the input field named &#8220;Phone&#8221;.</i></strong></p>
<pre class="brush: xml; title: ; notranslate" title="">

    &#60;div id=&#34;formContainer&#34;&#62;
        &#60;h1&#62;
            My First MVVM Web View &#60;br /&#62;
            now with Validation!&#60;/h1&#62;
        &#60;form id=&#34;myForm&#34; action=&#34;&#34;&#62;
        &#60;label&#62;
            First Name&#60;/label&#62;
        &#60;input type=&#34;text&#34; name=&#34;firstName&#34; data-bind=&#34;value: firstName, disabled:  isDisabled&#34; required validationMessage=&#34;please enter a first name&#34; /&#62;
        &#60;label&#62;
            Last Name&#60;/label&#62;
        &#60;input type=&#34;text&#34; name=&#34;lastName&#34; data-bind=&#34;value: lastName, disabled:  isDisabled&#34; required validationMessage=&#34;please enter a last name&#34; /&#62;
        &#60;label&#62;
            Email&#60;/label&#62;
        &#60;input type=&#34;email&#34; name=&#34;email&#34; data-bind=&#34;value: email, disabled:  isDisabled&#34; required /&#62;
        &#60;label&#62;
            Twitter&#60;/label&#62;
        &#60;input type=&#34;url&#34; name=&#34;twitter&#34; data-bind=&#34;value: twitter, disabled:  isDisabled&#34; required data-required-msg=&#34;please enter a {0}&#34; data-url-msg=&#34;please enter a valid url&#34; /&#62;
        &#60;label&#62;
            Site&#60;/label&#62;
        &#60;input type=&#34;url&#34; name=&#34;site&#34; data-bind=&#34;value: site, disabled:  isDisabled&#34; required validationMessage=&#34;please enter a {0}&#34; data-url-msg=&#34;please enter a valid url&#34;/&#62;
        &#60;label&#62;
            Address&#60;/label&#62;
        &#60;input type=&#34;text&#34; name=&#34;address&#34; data-bind=&#34;value: address, disabled:  isDisabled&#34; required validationMessage=&#34;please enter a {0}&#34; /&#62;
        &#60;label&#62;
            City&#60;/label&#62;
        &#60;input type=&#34;text&#34; name=&#34;city&#34; data-bind=&#34;value: city, disabled:  isDisabled&#34; required validationMessage=&#34;please enter a {0}&#34;/&#62;
        &#60;label&#62;
            State&#60;/label&#62;
        &#60;input type=&#34;text&#34; name=&#34;state&#34; data-bind=&#34;value: state, disabled:  isDisabled&#34; required validationMessage=&#34;please enter a {0}&#34;/&#62;
        &#60;label&#62;
            Zip&#60;/label&#62;
        &#60;input type=&#34;text&#34; name=&#34;zip&#34; data-bind=&#34;value: zip, disabled:  isDisabled&#34; required validationMessage=&#34;please enter a {0}&#34;/&#62;
        &#60;label&#62;
            Phone&#60;/label&#62;
        &#60;input type=&#34;tel&#34; name=&#34;phone&#34; pattern=&#34;\d{10}&#34;  data-bind=&#34;value: phone, disabled:  isDisabled&#34; required data-required-msg=&#34;please enter a {0} number&#34; data-pattern-msg=&#34;please enter a 10 digit phone number&#34;/&#62;
        &#60;label&#62;
            Lucky Number&#60;/label&#62;
        &#60;input type=&#34;number&#34; name=&#34;luckynumber&#34; data-bind=&#34;value: luckyNumber, disabled:  isDisabled&#34; required data-required-msg=&#34;please enter a lucky number&#34; data-max-msg=&#34;please enter a number less than 100&#34; min=&#34;1&#34; max=&#34;100&#34; /&#62;
        &#60;label&#62;
            Birth Date&#60;/label&#62;
        &#60;input type=&#34;date&#34; name=&#34;birthdate&#34; data-bind=&#34;value: birthDate, disabled:  isDisabled&#34; required validationMessage=&#34;please enter a {0}&#34; /&#62;
        &#60;label&#62;
            Occupation&#60;/label&#62;
        &#60;select name=&#34;occupation&#34; data-bind=&#34;source: occupations, value: occupation, disabled:  isDisabled&#34; required valdationMessage=&#34;please select a {0}&#34;&#62;
        &#60;/select&#62;
        &#60;br /&#62;
        &#60;br /&#62;
        &#60;input type=&#34;button&#34; value=&#34;Load&#34; data-bind=&#34;click: load&#34; /&#62;
        &#60;input type=&#34;button&#34; value=&#34;Edit&#34; data-bind=&#34;click: edit&#34; /&#62;
        &#60;input type=&#34;button&#34; value=&#34;Cancel&#34; data-bind=&#34;click: cancel&#34; /&#62;
        &#60;input type=&#34;button&#34; value=&#34;Reset&#34; data-bind=&#34;click: reset&#34; /&#62;
        &#60;button type=&#34;submit&#34; value=&#34;Submit&#34;&#62;Save&#60;/button&#62;
        &#60;/form&#62;
    &#60;/div&#62;

</pre>
<p>Notice that all we are doing here is really providing the Validator Framework with is validation messages for the type of validation. There is a convention that we need to follow which is marking the control with the attribute: data-[rule]-msg, [rule] just needs to be replaced with actual rule name so for example data-required-msg=&#8221;please enter a luckly number&#8221; will be the message that is displayed when there is no number in the input field and data-max-message=&#8221;please enter a number less than 100&#8243; will be the validation message that is shown if a user enters a number that is greater than 100. Now that all of our validation messages are setup let&#8217;s add our one line of script to get this all of our validations wired up (line 45).</p>
<pre class="brush: jscript; title: ; notranslate" title="">

    var myViewModel;
    $(document).ready(function () {
        myViewModel = kendo.observable({
            firstName: &#34;Long&#34;,
            lastName: &#34;Le&#34;,
            email: &#34;lelong37@gmail.com&#34;,
            twitter: &#34;twitter.com/lelong37&#34;,
            site: &#34;blog.longle.net&#34;,
            address: &#34;3737 Galatic Avenue&#34;,
            city: &#34;Cloud City&#34;,
            state: &#34;Texas&#34;,
            occupations: [&#34;&#34;, &#34;Hacker&#34;, &#34;Jedi&#34;, &#34;Ninja&#34;],
            occupation: &#34;Jedi&#34;,
            phone: &#34;1111111111&#34;,
            luckyNumber: 34,
            birthDate: null,
            isSaved: false,
            isDisabled: true,
            edit: function (e) {
                this.set(&#34;isDisabled&#34;, false);
            },
            cancel: function (e) {
                this.set(&#34;isDisabled&#34;, true);
            },
            reset: function (e) {
                this.set(&#34;firstName&#34;, null);
                this.set(&#34;lastName&#34;, null);
                this.set(&#34;email&#34;, null);
                this.set(&#34;twitter&#34;, null);
                this.set(&#34;site&#34;, null);
                this.set(&#34;address&#34;, null);
                this.set(&#34;city&#34;, null);
                this.set(&#34;state&#34;, null);
                this.set(&#34;zip&#34;, null);
                this.set(&#34;occupation&#34;, &#34;&#34;);
                this.set(&#34;phone&#34;, null);
                this.set(&#34;luckyNumber&#34;, null);
            },
            load: function (e) {
                LoadJohnDoesInfo();
            }
        });

        kendo.bind($(&#34;#myForm&#34;), myViewModel);
        var validator = $(&#34;#myForm&#34;).kendoValidator().data(&#34;kendoValidator&#34;);
    });

</pre>
<p>Now with our declaritive validation and one line of Javascript to wire everything up let&#8217;s give our form a spin. Let&#8217;s clear out our form by and try saving by clicking [Edit], [Reset] and [Save]. </p>
<p><a href="http://lelong37.files.wordpress.com/2012/08/8-1-2012-7-13-34-pm.png"><img src="http://lelong37.files.wordpress.com/2012/08/8-1-2012-7-13-34-pm.png?w=563&#038;h=889" alt="" title="8-1-2012 7-13-34 PM" width="563" height="889" class="alignnone size-full wp-image-1233" /></a></p>
<p>Let&#8217;s test out our messsages that are custom to a specific validation type by typing in an invalid Url for our Twitter, Site and invalid email address when filling out our form and clicking [Save].</p>
<p><a href="http://lelong37.files.wordpress.com/2012/08/8-1-2012-7-15-48-pm.png"><img src="http://lelong37.files.wordpress.com/2012/08/8-1-2012-7-15-48-pm.png?w=566&#038;h=867" alt="" title="8-1-2012 7-15-48 PM" width="566" height="867" class="alignnone size-full wp-image-1234" /></a></p>
<p>Notice how are validation messages are not the displaying the standard required messages but now they are validation messages specific to the type of validation. For example with the field &#8220;Lucky Number&#8221; the standard validation message was &#8220;please enter a lucky number&#8221; now that we actually typed in a value that is greater than the max attribute that was set to 100 we are getting the declartive validation message &#8220;please enter a number less than 100&#8243;. Also for the field [email] we also have typed in something however because we changed the input type to email (new with HTML5) out of the box the framework is displaying a standard message for us &#8220;email is not a valid email&#8221; even though we did not explicitly declare a validation message for email.</p>
<p>Now let&#8217;s fix all the fields with the correct values email, twitter, site, phone and lucky number and notice as we tab out of each field our validation messages dissapear and we are able to post the form.</p>
<p><a href="http://lelong37.files.wordpress.com/2012/08/8-1-2012-7-18-34-pm.png"><img src="http://lelong37.files.wordpress.com/2012/08/8-1-2012-7-18-34-pm.png?w=570&#038;h=859" alt="" title="8-1-2012 7-18-34 PM" width="570" height="859" class="alignnone size-full wp-image-1237" /></a></p>
<p>Last but not least we can manually invoke the Validator by invoking the validate() method, let&#8217;s go ahead and rewire our click button to go ahead and validate our form as well as display a message to the user.</p>
<pre class="brush: jscript; title: ; notranslate" title="">

        $(&#34;button&#34;).click(function (e) {
            e.preventDefault();
            if (validator.validate()) {
                alert(&#34;Your form is golden!&#34;);
            } else {
                alert(&#34;Your form has errors!&#34;);
            }
        });

</pre>
<p>Let&#8217;s give this a try.</p>
<p><a href="http://lelong37.files.wordpress.com/2012/08/8-1-2012-7-29-08-pm.png"><img src="http://lelong37.files.wordpress.com/2012/08/8-1-2012-7-29-08-pm.png?w=572&#038;h=894" alt="" title="8-1-2012 7-29-08 PM" width="572" height="894" class="alignnone size-full wp-image-1241" /></a></p>
<p>Happy Coding! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Download: <a href="https://skydrive.live.com/redir?resid=949A1C97C2A17906!1976" title="https://skydrive.live.com/redir?resid=949A1C97C2A17906!1976" target="_blank"></a></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[My Start on ASP.NET MVC3 ]]></title>
<link>http://mytechlifedays.wordpress.com/2012/07/31/my-start-on-asp-net-mvc3/</link>
<pubDate>Tue, 31 Jul 2012 04:15:32 +0000</pubDate>
<dc:creator>mytechlifedays</dc:creator>
<guid>http://mytechlifedays.wordpress.com/2012/07/31/my-start-on-asp-net-mvc3/</guid>
<description><![CDATA[So finally I am taking a plunge .. from ASP.Net , Umbraco , MS CRM .. and of course my good buddies]]></description>
<content:encoded><![CDATA[So finally I am taking a plunge .. from ASP.Net , Umbraco , MS CRM .. and of course my good buddies]]></content:encoded>
</item>
<item>
<title><![CDATA[Strongly typed models on your layout]]></title>
<link>http://dtoncode.wordpress.com/2012/07/30/strongly-typed-models-on-your-layout/</link>
<pubDate>Mon, 30 Jul 2012 22:14:35 +0000</pubDate>
<dc:creator>D^t</dc:creator>
<guid>http://dtoncode.wordpress.com/2012/07/30/strongly-typed-models-on-your-layout/</guid>
<description><![CDATA[One of the early issues I disliked when moving to .net&#8217;s MVC was the lack of strongly typed ob]]></description>
<content:encoded><![CDATA[<p>One of the early issues I disliked when moving to .net&#8217;s MVC was the lack of strongly typed objects available in layout pages. A lot of times I&#8217;ll want to display failry static, session(ish) type information in a many places &#8220;around&#8221; the main content area.</p>
<p>Information like the current users name, email and even other not so generic information like permissions (we rolled our own permissions architecture) or current context (our website has many &#8220;portals&#8221;) all seemed like fair game. I also noticed many times we&#8217;ll need this information in the main content view or even on a  partial/ajax request.</p>
<p>A couple solutions came to mind. </p>
<p>I initially created many partial actions which retrieved the specific information I needed for the particular area but soon found that to be too cumbersome. Even if all the information I needed was cached in nHibernate for the entire request, why must I go a round about way to get it each time.</p>
<p>Another solution was to stick what I needed in the context object, or even the &#8216;He-Who-Must-Not-Be-Named&#8217; &#8211; señor ViewBag. Again though leading back to my original thesis &#8211; I wanted this to be typed safe &#8211; so I finally settled on this quick and simple solution.</p>
<p>First I created a simple view model, added any dependencies and populated it with the info I&#8217;d want available to my layouts and views.</p>
<pre class="brush: csharp; title: ; notranslate" title="">
public class BaseViewModel
{
   private readonly IContextRepository _contextRepository;

   public BaseViewModel(IContextRepository contextRepository)
   {
      _contextRepository = contextRepository;
      SelectedContext = _contextRepository.GetCurrent();
   }
   // assume for the sake of the example a ContextViewModel is just a simple dto with an Id and Name representing a context business object
   public ContextViewModel SelectedContext { get; private set;  }
}
</pre>
<p>Then in my base controller, during the <strong>OnActionExecuting</strong> I create the BaseViewModel using my resolver. It&#8217;s important to note that the BaseViewModel (and all of it&#8217;s properties) gets created <strong>between the unitOfWork transaction</strong> to ensure I&#8217;m not accessing the database at the view level. If there&#8217;s questions about why it&#8217;s important, I&#8217;ll make another blog post soon to respond. </p>
<pre class="brush: csharp; title: ; notranslate" title="">
public class BaseController : Controller
{
  protected BaseViewModel ModelBase { get; private set; }

  private readonly IMapService _mapService = Resolver.Get&#60;IMapService&#62;();
  private IUnitOfWork _unitOfWork;

  protected override void OnResultExecuting(ResultExecutingContext filterContext)
  {
    var contextItems = filterContext.HttpContext.Items;
    if (contextItems[&#34;ModelBase&#34;] == null)
      contextItems[&#34;ModelBase&#34;] = ModelBase;
    base.OnResultExecuting(filterContext);
  }

  protected override void OnActionExecuting(ActionExecutingContext filterContext)
  {
    _unitOfWork = Resolver.Get&#60;IUnitOfWork&#62;();
    _unitOfWork.BeginTransaction();
            
    ModelBase = new BaseViewModel(Resolver.Get&#60;IContextRepository&#62;());
            
    base.OnActionExecuting(filterContext);
  }
  //...
}
</pre>
<p>After creating it, I simply place it in the contextItems dictionary to be used by the views &#8211; simple as that. This allows type safe, transaction safe references to information in the layouts, and really all over the place.</p>
<p>_layout.cshtml</p>
<pre class="brush: xml; title: ; notranslate" title="">
...
&#60;div&#62;Hey there you're in the @ModelBase.SelectedContext.Name section of our site!&#60;/div&#62;
...
</pre>
<p>The naming is especially nice since intellisense will pick up the BaseViewModel when the developer types &#8220;Model&#8221; as he&#8217;ll see &#8220;ModelBase&#8221; in the drop down and hopefully remember to use it. It&#8217;s also made refactoring quite a bit easier as we now have one place to make modifications to retrieving that commonly used information.</p>
<p><strong>(Now of course with great power&#8230;)</strong><br />
Make sure you <strong>only</strong> put in to this baseViewModel what you&#8217;ll be accessing quite often (nearly if not every request) otherwise obviously you won&#8217;t get as much out of it as you could. It&#8217;s also recommended, like always, <strong>if you are working with a view model of any kind, keep it to primitives or dtos of primitives </strong>mapped via nHibernate or AutoMapper. </p>
<p>Please don&#8217;t expose your entire user/company/kitchenSink object using this method as I&#8217;ll plead the 5th. =P</p>
<p>-D^t</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Telerik's Kendo UI Web MVVM Framework Rocks!]]></title>
<link>http://blog.longle.net/2012/07/28/teleriks-kendo-ui-web-mvvm-framework-rocks/</link>
<pubDate>Sat, 28 Jul 2012 06:44:35 +0000</pubDate>
<dc:creator>Le</dc:creator>
<guid>http://blog.longle.net/2012/07/28/teleriks-kendo-ui-web-mvvm-framework-rocks/</guid>
<description><![CDATA[For those of us that fell in love with the awesome binding power that WPF and Silverlight brought to]]></description>
<content:encoded><![CDATA[<p>For those of us that fell in love with the awesome binding power that <a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx" target="_blank">WPF</a> and <a href="http://www.silverlight.net/learn/advanced-techniques/the-mvvm-pattern/using-the-mvvm-pattern-in-silverlight-applications" target="_blank">Silverlight</a> brought to the masses with <a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx" target="blank">MVVM (Model-ViewModel-Model)</a>, well I have good news for you folks. <a href="http://www.telerik.com/" target="_blank">Telerik</a> has their <a href="http://docs.kendoui.com/api/framework/kendo" target="_blank">Kendo UI Web MVVM Framework</a> so that you can leverage MVVM in your (MVC) web apps! </p>
<p>Quick synopsis on MVVM for those of us that are new to it (especially MVC devs) and in the interest of time I&#8217;ll try to do this in a 60 second nutshell. So when working with a view whether it be in WPF, Silverlight, and now MVC, you can declaritively set which controls bind to which properties to your ViewModel (simply a JSON object with properties). So for example I can set a DropDownList (select) control on my view to bind directly to a property of my ViewModel that is a collection.</p>
<p>So let&#8217;s get right to it with a few simple examples.</p>
<p>First add a script references for <a href="http://jquery.com/" target="_blank">jQuery</a> and Kendo UI, here are some links for Microsoft&#8217;s and Teleriks&#8217; CDN&#8217;s for these scripts.</p>
<ul>
<li><a href="http://www.asp.net/ajaxlibrary/cdn.ashx" target="_blank">http://www.asp.net/ajaxlibrary/cdn.ashx</a></li>
<li>
<a href="http://www.kendoui.com/documentation/javascript-dependencies.aspx" target="_blank">http://www.kendoui.com/documentation/javascript-dependencies.aspx</a></li>
</ul>
<pre class="brush: xml; highlight: [8,9]; title: ; notranslate" title="">

&#60;!DOCTYPE html PUBLIC &#34;-//W3C//DTD XHTML 1.0 Transitional//EN&#34; &#34;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#34;&#62;
&#60;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;&#62;
&#60;head&#62;
    &#60;title&#62;Kendo UI Web MVVM&#60;/title&#62;
&#60;/head&#62;
&#60;body&#62;
&#60;/body&#62;
&#60;script src=&#34;http://code.jquery.com/jquery-1.7.1.min.js&#34;&#62;&#60;/script&#62;
&#60;script src=&#34;http://cdn.kendostatic.com/2012.2.710/js/kendo.all.min.js&#34;&#62;&#60;/script&#62;
&#60;/html&#62;

</pre>
<p>Now let&#8217;s create a simple form.</p>
<pre class="brush: xml; title: ; notranslate" title="">

&#60;!DOCTYPE html PUBLIC &#34;-//W3C//DTD XHTML 1.0 Transitional//EN&#34; &#34;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&#34;&#62;
&#60;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;&#62;
&#60;head&#62;
    &#60;title&#62;Kendo UI Web MVVM&#60;/title&#62;
    &#60;script src=&#34;http://code.jquery.com/jquery-1.7.1.min.js&#34; type=&#34;text/javascript&#34;&#62;&#60;/script&#62;
    &#60;script src=&#34;http://cdn.kendostatic.com/2012.2.710/js/kendo.all.min.js&#34; type=&#34;text/javascript&#34;&#62;&#60;/script&#62;
    &#60;style type=&#34;text/css&#34;&#62;
        body
        {
            font-family: Arial;
        }
        label
        {
            display: block;
            margin-top: 10px;
        }
        #formContainer
        {
            background-color: #F2F7F9;
            width: 400px;
            padding: 20px;
            margin: 50px auto;
            border: 6px solid #8FB5C1;
            border-radius: 15px;
            position: relative;
        }
    &#60;/style&#62;
&#60;/head&#62;
&#60;body&#62;
    &#60;div id=&#34;formContainer&#34;&#62;
        &#60;h1&#62;My First MVVM Web View!&#60;/h1&#62;
        &#60;form id=&#34;myForm&#34; action=&#34;&#34;&#62;
        &#60;label&#62;
            First Name&#60;/label&#62;
        &#60;input type=&#34;text&#34; /&#62;
        &#60;label&#62;
            Last Name&#60;/label&#62;
        &#60;input type=&#34;text&#34;  /&#62;
        &#60;label&#62;
            Email&#60;/label&#62;
        &#60;input type=&#34;text&#34;  /&#62;
        &#60;label&#62;
            Twitter&#60;/label&#62;
        &#60;input type=&#34;text&#34;  /&#62;
        &#60;label&#62;
            Site&#60;/label&#62;
        &#60;input type=&#34;text&#34; /&#62;
        &#60;label&#62;
            Address&#60;/label&#62;
        &#60;input type=&#34;text&#34; /&#62;
        &#60;label&#62;
            City&#60;/label&#62;
        &#60;input type=&#34;text&#34; /&#62;
        &#60;label&#62;
            State&#60;/label&#62;
        &#60;input type=&#34;text&#34; /&#62;
        &#60;label&#62;
            Zip&#60;/label&#62;
        &#60;input type=&#34;text&#34; /&#62;
        &#60;label&#62;
            Occupation&#60;/label&#62;
        &#60;select&#62;
        &#60;/select&#62;
        &#60;br /&#62;
        &#60;br /&#62;
        &#60;input type=&#34;button&#34; /&#62;
        &#60;input type=&#34;button&#34; /&#62;
        &#60;input type=&#34;button&#34; /&#62;
         &#60;input type=&#34;button&#34; /&#62;
        &#60;/form&#62;
    &#60;/div&#62;
&#60;/body&#62;

&#60;/html&#62;

</pre>
<p>Now let&#8217;s create a ViewModel (JavaScript JSON object or class if you will) with some default values for our View (in this case our form) to bind to. We will also add some methods to our ViewModel so that we can bind our buttons that are on our view too.</p>
<pre class="brush: jscript; highlight: [18]; title: ; notranslate" title="">

  &#60;script language=&#34;javascript&#34; type=&#34;text/javascript&#34;&#62;

    var myViewModel;
    $(document).ready(function () {
        myViewModel = kendo.observable({
            firstName: &#34;Long&#34;,
            lastName: &#34;Le&#34;,
            email: &#34;lelong37@gmail.com&#34;,
            twitter: &#34;twitter.com/lelong37&#34;,
            site: &#34;blog.longle.net&#34;,
            address: &#34;3737 Galatic Avenue&#34;,
            city: &#34;Cloud City&#34;,
            state: &#34;Texas&#34;,
            occupations: [&#34;Please Select&#34;, &#34;Hacker&#34;, &#34;Jedi&#34;, &#34;Ninja&#34;],
            occupation: &#34;Jedi&#34;,
        });

        kendo.bind($(&#34;#myForm&#34;), myViewModel);
    });

&#60;/script&#62;

</pre>
<p>Note: Line 18 is what will bind our form to our ViewModel, if your wondering why nothing is happening yet it&#8217;s because we are missing once more step which is to provide the binding (mapping) information, which will map our controls to our ViewModel. The beauty here is we will do this declaritively with without code.</p>
<p>Our View will have two modes: read-only and edit, so we will bind our controls for where each control will get and set it&#8217;s values to and another binding for enabling and disabling them.</p>
<pre class="brush: xml; title: ; notranslate" title="">

    &#60;div id=&#34;formContainer&#34;&#62;
        &#60;h1&#62;My First MVVM Web View!&#60;/h1&#62;
        &#60;form id=&#34;myForm&#34; action=&#34;&#34;&#62;
        &#60;label&#62;
            First Name&#60;/label&#62;
        &#60;input type=&#34;text&#34; data-bind=&#34;value: firstName, disabled:  isDisabled&#34; /&#62;
        &#60;label&#62;
            Last Name&#60;/label&#62;
        &#60;input type=&#34;text&#34; data-bind=&#34;value: lastName, disabled:  isDisabled&#34; /&#62;
        &#60;label&#62;
            Email&#60;/label&#62;
        &#60;input type=&#34;text&#34; data-bind=&#34;value: email, disabled:  isDisabled&#34; /&#62;
        &#60;label&#62;
            Twitter&#60;/label&#62;
        &#60;input type=&#34;text&#34; data-bind=&#34;value: twitter, disabled:  isDisabled&#34; /&#62;
        &#60;label&#62;
            Site&#60;/label&#62;
        &#60;input type=&#34;text&#34; data-bind=&#34;value: site, disabled:  isDisabled&#34; /&#62;
        &#60;label&#62;
            Address&#60;/label&#62;
        &#60;input type=&#34;text&#34; data-bind=&#34;value: address, disabled:  isDisabled&#34; /&#62;
        &#60;label&#62;
            City&#60;/label&#62;
        &#60;input type=&#34;text&#34; data-bind=&#34;value: city, disabled:  isDisabled&#34; /&#62;
        &#60;label&#62;
            State&#60;/label&#62;
        &#60;input type=&#34;text&#34; data-bind=&#34;value: state, disabled:  isDisabled&#34; /&#62;
        &#60;label&#62;
            Zip&#60;/label&#62;
        &#60;input type=&#34;text&#34; data-bind=&#34;value: zip, disabled:  isDisabled&#34; /&#62;
        &#60;label&#62;
            Occupation&#60;/label&#62;
        &#60;select data-bind=&#34;source: occupations, value: occupation, disabled:  isDisabled&#34;&#62;
        &#60;/select&#62;
        &#60;br /&#62;
        &#60;br /&#62;
        &#60;input type=&#34;button&#34; value=&#34;Load&#34; /&#62;
        &#60;input type=&#34;button&#34; value=&#34;Edit&#34; /&#62;
        &#60;input type=&#34;button&#34; value=&#34;Cancel&#34; /&#62;
         &#60;input type=&#34;button&#34; value=&#34;Reset&#34; /&#62;
        &#60;/form&#62;
    &#60;/div&#62;

</pre>
<p>Now if we refresh the page we that our View is not bound to our ViewModel&#8230;!</p>
<p><a href="http://lelong37.files.wordpress.com/2012/07/7-28-2012-12-26-45-am.png"><img src="http://lelong37.files.wordpress.com/2012/07/7-28-2012-12-26-45-am.png?w=492&#038;h=712" alt="" title="7-28-2012 12-26-45 AM" width="492" height="712" class="alignnone size-full wp-image-1136" /></a></p>
<p>Note: Notice that our form is in read-only mode, all of our controls are disabled for editing because the disabled attribute is bound to the isDisabled property in our ViewModel whose default value is set to true.</p>
<p>For those of us that are ASP.NET MVC developers, the answer is yes you can get and post your ViewModel back as JSON using jQuery from and to an actions on your controller!</p>
<p>Now let&#8217;s demonstrate binding our buttons to methods on our ViewModel, first let&#8217;s add a couple of methods to our ViewModel (edit, cancel, reset, and load)</p>
<ul>
<li><strong>edit</strong>, will enabled our View for editing</li>
<li><strong>cancel</strong>, will set our View back to read-only mode</li>
<li><strong>reset</strong>, will clear out our View</li>
<li><strong>load</strong>, will load John Doe&#8217;s information into our View (obviously here you could load this from using a &#8220;GET&#8221; to an action off of your controller)</li>
</ul>
<pre class="brush: jscript; title: ; notranslate" title="">

    var myViewModel;
    $(document).ready(function () {
        myViewModel = kendo.observable({
            firstName: &#34;Long&#34;,
            lastName: &#34;Le&#34;,
            email: &#34;lelong37@gmail.com&#34;,
            twitter: &#34;twitter.com/lelong37&#34;,
            site: &#34;blog.longle.net&#34;,
            address: &#34;3737 Galatic Avenue&#34;,
            city: &#34;Cloud City&#34;,
            state: &#34;Texas&#34;,
            occupations: [&#34;Please Select&#34;, &#34;Hacker&#34;, &#34;Jedi&#34;, &#34;Ninja&#34;],
            occupation: &#34;Jedi&#34;,
            isSaved: false,
            isDisabled: true,
            edit: function (e) {
                this.set(&#34;isDisabled&#34;, false);
            },
            cancel: function (e) {
                this.set(&#34;isDisabled&#34;, true);
            },
            reset: function (e) {
                this.set(&#34;firstName&#34;, null);
                this.set(&#34;lastName&#34;, null);
                this.set(&#34;email&#34;, null);
                this.set(&#34;twitter&#34;, null);
                this.set(&#34;site&#34;, null);
                this.set(&#34;address&#34;, null);
                this.set(&#34;city&#34;, null);
                this.set(&#34;state&#34;, null);
                this.set(&#34;zip&#34;, null);
                this.set(&#34;occupation&#34;, &#34;Please Select&#34;);
            },
            load: function (e) {
                LoadJohnDoesInfo();
            }
        });

        kendo.bind($(&#34;#myForm&#34;), myViewModel);
    });

    function LoadJohnDoesInfo() {
        myViewModel.set(&#34;firstName&#34;, &#34;John&#34;);
        myViewModel.set(&#34;lastName&#34;, &#34;Doe&#34;);
        myViewModel.set(&#34;email&#34;, &#34;jdoe@skyranch.com&#34;);
        myViewModel.set(&#34;twitter&#34;, &#34;twitter.com/jedi&#34;);
        myViewModel.set(&#34;site&#34;, &#34;starwars.com&#34;);
        myViewModel.set(&#34;address&#34;,  &#34;1212 SkyRanch&#34;);
        myViewModel.set(&#34;state&#34;, &#34;California&#34;);
        myViewModel.set(&#34;zip&#34;, &#34;98000&#34;);
        myViewModel.set(&#34;occupation&#34;, &#34;Jedi&#34;);
    }

</pre>
<p>Add our binding meta-data to our buttons declaritively.</p>
<pre class="brush: xml; title: ; notranslate" title="">

        &#60;input type=&#34;button&#34; value=&#34;Load&#34; data-bind=&#34;click: load&#34; /&#62;
        &#60;input type=&#34;button&#34; value=&#34;Edit&#34; data-bind=&#34;click: edit&#34; /&#62;
        &#60;input type=&#34;button&#34; value=&#34;Cancel&#34; data-bind=&#34;click: cancel&#34; /&#62;
        &#60;input type=&#34;button&#34; value=&#34;Reset&#34; data-bind=&#34;click: reset&#34; /&#62;


</pre>
<p>So let&#8217;s invoke some our methods on our ViewModel and give our button&#8217;s a run for their money.</p>
<p>Now let&#8217;s click on the [Load] button and here I just wanted to demonstrating that all we need to do here to update the View is interact with the ViewModel, any changes to the ViewModel and the View automatically updates because they are bound together, which is the magic and essense of the MVVM pattern!</p>
<p>Our load method on our ViewModel.</p>
<pre class="brush: jscript; title: ; notranslate" title="">

            load: function (e) {
                LoadJohnDoesInfo();
            }

</pre>
<p>Which turns around and invokes our LoadJohnDoesInfo method and set&#8217;s his data on our ViewModel.</p>
<pre class="brush: jscript; title: ; notranslate" title="">

    function LoadJohnDoesInfo() {
        myViewModel.set(&#34;firstName&#34;, &#34;John&#34;);
        myViewModel.set(&#34;lastName&#34;, &#34;Doe&#34;);
        myViewModel.set(&#34;email&#34;, &#34;jdoe@skyranch.com&#34;);
        myViewModel.set(&#34;twitter&#34;, &#34;twitter.com/jedi&#34;);
        myViewModel.set(&#34;site&#34;, &#34;starwars.com&#34;);
        myViewModel.set(&#34;address&#34;, &#34;1212 SkyRanch&#34;);
        myViewModel.set(&#34;state&#34;, &#34;California&#34;);
        myViewModel.set(&#34;zip&#34;, &#34;98000&#34;);
        myViewModel.set(&#34;occupation&#34;, &#34;Jedi&#34;);
    }

</pre>
<p><a href="http://lelong37.files.wordpress.com/2012/07/7-28-2012-1-06-55-am.png"><img src="http://lelong37.files.wordpress.com/2012/07/7-28-2012-1-06-55-am.png?w=491&#038;h=704" alt="" title="7-28-2012 1-06-55 AM" width="491" height="704" class="alignnone size-full wp-image-1150" /></a></p>
<p>Notice when the View first loads our entire form is disabled for our read-only mode and when we click [Edit] all of our controls that had the binding for disabled that was bound to the isDisabled property on our ViewModel which be default is set to true. Once we click on the Edit button the isDisabled property is set to true enabling all of our controls for edit mode.</p>
<p>Our declaritive binding on one of our controls.</p>
<pre class="brush: xml; title: ; notranslate" title="">

&#60;input type=&#34;text&#34; data-bind=&#34;value: firstName, disabled:  isDisabled&#34; /&#62;

</pre>
<p>The Edit method that is invoked when clicking the [Edit] button.</p>
<pre class="brush: jscript; title: ; notranslate" title="">

            edit: function (e) {
                this.set(&#34;isDisabled&#34;, false);
            },

</pre>
<p><a href="http://lelong37.files.wordpress.com/2012/07/7-28-2012-12-59-13-am1.png"><img src="http://lelong37.files.wordpress.com/2012/07/7-28-2012-12-59-13-am1.png?w=502&#038;h=710" alt="" title="7-28-2012 12-59-13 AM" width="502" height="710" class="alignnone size-full wp-image-1152" /></a></p>
<p>Hitting the [Reset] button will simply invoke the reset method on our ViewModel which clears out all our properties by setting them null values and again our View is automagically updated because it is bound to our ViewModel.</p>
<pre class="brush: jscript; title: ; notranslate" title="">

            reset: function (e) {
                this.set(&#34;firstName&#34;, null);
                this.set(&#34;lastName&#34;, null);
                this.set(&#34;email&#34;, null);
                this.set(&#34;twitter&#34;, null);
                this.set(&#34;site&#34;, null);
                this.set(&#34;address&#34;, null);
                this.set(&#34;city&#34;, null);
                this.set(&#34;state&#34;, null);
                this.set(&#34;zip&#34;, null);
                this.set(&#34;occupation&#34;, &#34;Please Select&#34;);
            },

</pre>
<p><a href="http://lelong37.files.wordpress.com/2012/07/7-28-2012-1-15-11-am.png"><img src="http://lelong37.files.wordpress.com/2012/07/7-28-2012-1-15-11-am.png?w=498&#038;h=709" alt="" title="7-28-2012 1-15-11 AM" width="498" height="709" class="alignnone size-full wp-image-1155" /></a></p>
<p>Well great, I know we aren&#8217;t doing anything ground breaking here, however this post is really just to illustrate MVVM on the client-side using Telerik&#8217;s Kendo UI Web MVVM Framework and ellaborate on how we can really just work with the ViewModel to update the View vice- versa any updates to the View will update our ViewModel because they are &#8220;bound&#8221; together using MVVM.</p>
<p>Last but not least, even though the Kendo UI Framework was written with jQuery, notice how we didn&#8217;t have to explicitly use any jQuery or Javascript to set or get any values from our controls. I&#8217;m not at all saying jQuery is a bad thing, however when developing you probably want to be coding something that is immediately adding business value rather than coding jQuery selectors to get and and set values in your View right..? :p</p>
<p>Happy coding&#8230;! <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Download sample code: <a href="https://skydrive.live.com/redir?resid=949A1C97C2A17906!1951" target="_blank">https://skydrive.live.com/redir?resid=949A1C97C2A17906!1951</a></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Entrevista a Frutsy]]></title>
<link>http://torneola.wordpress.com/2012/07/27/entrevista-a-frutsy/</link>
<pubDate>Fri, 27 Jul 2012 06:17:06 +0000</pubDate>
<dc:creator>torneola</dc:creator>
<guid>http://torneola.wordpress.com/2012/07/27/entrevista-a-frutsy/</guid>
<description><![CDATA[Que tal como estas!!! Mira aqui te va la entrevista con uno de los jugadores que mejor representaron]]></description>
<content:encoded><![CDATA[<p><a href="http://torneola.files.wordpress.com/2012/07/frutsypic.jpg"><img class="alignnone size-full wp-image-141" title="frutsypic" src="http://torneola.files.wordpress.com/2012/07/frutsypic.jpg?w=450&#038;h=298" alt="" width="450" height="298" /></a></p>
<p>Que tal como estas!!!</p>
<p>Mira aqui te va la entrevista con uno de los jugadores que mejor representaron a Mexico y se hizo toda una revolucion por su gran desempeno en el torneo Evolution 2012, me refiero claro a Frutsy..</p>
<p>Que onda frutsy, que te parecio el evo?</p>
<p><strong>El evo me pareció increíble!!! es una experiencia única que tengo que repetir</strong></p>
<p>Esperabas llegar tan lejos?</p>
<p><strong>Esperaba ganar pero minimo siempre dije que iba a estar en top 8 y lo logre</strong></p>
<p>Que sentiste llegar al top 8?</p>
<p><strong>Mucho orgullo porque logre estar ahi, no tienen idea del orgullo y felicidad que se siente </strong></p>
<p>Que jugadores se te hicieron interesantes o de sorpresa?</p>
<p><strong>Interesantes los japoneses y el chileno kane, los de sorpresa&#8230; los japoneses jajaja</strong></p>
<p>Con quien retaste? Con quien te quedaste con ganas de retar?</p>
<p><strong>Rete con muchos de alto nivel pero me quede con ganas de retar con chris G y justin wong</strong></p>
<p>Que tal ser parte del team mexico? Que piensas al respecto del team?</p>
<p><strong>Es exelente, tuvimos una hermandad increible aun sin conocernos y pienso que son grandiosos todos</strong></p>
<p>Que es el Team Asteroides y como nace? Y que hace?</p>
<p><strong>El Team Asteroides es un grupo de amigos que juega retas de cualquier juego de peleas sin excluir a nadie. Nació la idea hace algunos años gracias a la propuesta que hice sobre hacer un equipo representativo para los torneos ya que nosotros jugabamos en un local de maquinas que se llamaba asteroides, mi idea fue rechazada entonces y hasta hace poco&#8230; mas o menos en Enero que formabamos parte de elite mexico tuvimos algunos desacuerdos y nos sacaron del grupo asi que como ya teníamos una cierta comunidad pues volví a proponer que hicieramos team asteroides y esta ves aceptaron. Que hacemos? Pues organizamos torneos de UMvC3, retas en las noches, ranbats los domingos (mini torneos tipo una liga), enseñamos a jugar a los que quieren aprender, etc&#8230; el chiste es ayudar a la comunidad</strong></p>
<p>Eres del DF?</p>
<p><strong>Si, soy del df</strong></p>
<p>De donde viene el nombre de frutsy?</p>
<p><strong>Quisiera saberlo tambien jajaja la cosa es que en un torneo cuando me preguntaron mi apodo para inscribirme un amigo de inmediato dijo frutsy!!! y yo lo voltie a ver muy sorprendido y le pregunte que quien me decía asi ya que segun yo no tenía apodo y el dijo que asi me decian en asteroides&#8230; y se me quedo ya que en ese torneo hice un buen papel tambien</strong></p>
<p>Regresaras al evo del ano que viene?</p>
<p><strong>Me encantaría volver pero debo ver mi situacion para ese momento asi que por ahora no puedo asegurar nada</strong></p>
<p><strong> </strong></p>
<p>A donde te gustaria ir a retar?</p>
<p><strong>Me gustaría ir a cualquier torneo donde pueda conocer distintos lugares y tener siempre experiencias nuevas y porsupuesto jugar con todo lo que tengo</strong></p>
<p>Ah cambiado tu vida regresando del evo?</p>
<p><strong>Pues claro que ha cambiado&#8230; almenos en esto de la escena de peleas pues mas personas quieren aprender a jugar y se acercan mas a nosotros y eso me pone muy contento</strong></p>
<p>Como vez el nivel de mexico en marvel en comparacion con EEUU?</p>
<p><strong>El nivel de EU es grande pero aqui estoy seguro que se sorprenderian de ver que hay muchos que los pondrían en apuros</strong></p>
<p>Que crees que hace falta en mexico?</p>
<p><strong>Falta apoyo tanto animico ya que muchos piensan que porque somos mexicanos no vamos a ganar y eso no es cierto, como economico ya que si hubieran patrocinios como los hay alla se podrian ver mejores eventos de forma local y mayor promocion al nivel mexicano</strong></p>
<p>Cual es tu proxima meta?</p>
<p><strong>Pues mi meta siempre sera mejorar y juntar la comunidad de juego, si hablamos de torneos pues ahora si que a los que la vida me lleve</strong></p>
<p>Donde veremos al frutsy proximamente?</p>
<p><strong>Pues me veran donde haya torneos y mientras tenga la posibilidad de asistir ahi me veran, por ejemplo la semana pasada fui a acapulco a jugar un torneo y el 4 de agosto tengo el torneo Nuclear aqui en el DF en la expo reforma</strong></p>
<p>Tienes twitter?</p>
<p><strong>Mi twitter es @frutsy16</strong></p>
<p>Algunas palabras que quieras compartir con tus fans?</p>
<p><strong>Jajaja fans??? caray que lindo se escucha eso jajaja. pues mas bien le quiero decir a todos que le echen ganas a lo que deveras quieran porque nada es inalcanzable y almenos yo ya hice algo de lo que mas me apasiona y esto me demuestra que los limites son autoimpuestos, las cosas pueden ser dificiles pero con voluntad se pueden lograr</strong></p>
<p><strong> </strong></p>
<p>Muchas gracias Frutsy y si lo quieren seguir siganlo en @frutsy16<a href="https://twitter.com/frutsy16"><s><br />
</s></a></p>
<p>Y claro siganme a mi @neopenny para cualquier duda y sugerencia del blog, hasta la proxima!!!</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[MVC 3, EF Code First and SQL CE:  Putting it all together]]></title>
<link>http://coderkelly.wordpress.com/2012/07/24/mvc-3-ef-code-first-and-sql-ce-putting-it-all-together/</link>
<pubDate>Tue, 24 Jul 2012 20:20:10 +0000</pubDate>
<dc:creator>myprm</dc:creator>
<guid>http://coderkelly.wordpress.com/2012/07/24/mvc-3-ef-code-first-and-sql-ce-putting-it-all-together/</guid>
<description><![CDATA[If I don’t write about this incident, I’ll inevitably repeat it.  So here we go: Problem: SQL CE dat]]></description>
<content:encoded><![CDATA[<p>If I don’t write about this incident, I’ll inevitably repeat it.  So here we go:</p>
<p><strong>Problem:<br />
</strong>SQL CE database was not getting created when using using Entity Framework’s Code First paradigm within an MVC application.</p>
<p><strong>Details:<br />
</strong>Initial error stated:</p>
<blockquote><p><em>A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 &#8211; Error Locating Server/Instance Specified)</em></p></blockquote>
<p>However, the Inner Exception specified:</p>
<blockquote><p><em>ProviderIncompatibleException: The provider did not return a ProviderManifestToken string.</em></p></blockquote>
<p><strong>Resolution:<br />
</strong>Essentially, what I was lacking was a <strong>Connection String </strong>to tell Entity Framework where to create the Database.</p>
<p>I used the following code in the root-level <em>Web.config </em>file to remedy the error:</p>
<div id="scid:C89E2BDB-ADD3-4f7a-9810-1B7EACF446C1:97af9118-b4ee-4294-8133-2cd6b1cb8a91" class="wlWriterEditableSmartContent" style="margin:0;display:inline;float:none;padding:0;">
<pre class="brush: xml; pad-line-numbers: true; title: ; notranslate" title="">
&#60;add name=&#34;SalesQuoteDB&#34; connectionString=&#34;Data Source=&#124;DataDirectory&#124;SalesQuote.sdf&#34; providerName=&#34;System.Data.SqlServerCe.4.0&#34;/&#62;
</pre>
</div>
<p>Now all seems well with the world.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[ASP.NET MVC&ndash; Display the contents of a CSV file in a Telerik Grid]]></title>
<link>http://mvcdotnet.wordpress.com/2012/07/23/asp-net-mvc-display-the-contents-of-a-csv-file-in-a-telerik-grid/</link>
<pubDate>Mon, 23 Jul 2012 07:03:26 +0000</pubDate>
<dc:creator>Hattan</dc:creator>
<guid>http://mvcdotnet.wordpress.com/2012/07/23/asp-net-mvc-display-the-contents-of-a-csv-file-in-a-telerik-grid/</guid>
<description><![CDATA[In this article I’m going to show you how to build an ASP.NET MVC web application that will allow yo]]></description>
<content:encoded><![CDATA[<p>In this article I’m going to show you how to build an ASP.NET MVC web application that will allow you to upload a CSV file and display the results in a Telerik Grid. We’re going to be using two libraries to help us with this task.</p>
<ul>
<li><a href="http://www.aspnetperformance.com/post/LINQ-to-CSV-library.aspx">LinqToCsv</a> which is going to help us parse the csv file.</li>
<li><a href="http://www.telerik.com/products/aspnet-mvc.aspx">Telerik Extensions for ASP.NET MVC</a>. This is going to provide us with a powerful grid in which we can render the results.</li>
</ul>
<p>Let’s start by downloading and installing the Telerik Extensions, you can either download a free trial or use the open source version of the extensions. Be sure to read the license on the open source version before using it in your applications.</p>
<p>The library add a Visual Studio extension  as well as new project types. This makes it very easy to use the Telerik extensions in a new project.</p>
<p>After downloading and installing the extensions, let’ go ahead and create a new Visual Studio ASP.NET MVC3 Web Application called “CsvToGrid”.</p>
<p><a href="http://mvcdotnet.files.wordpress.com/2012/07/image.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://mvcdotnet.files.wordpress.com/2012/07/image_thumb.png?w=398&#038;h=249" alt="image" width="398" height="249" border="0" /></a></p>
<p>Because we installed the Telerik Extensions for ASP.NET MVC we should see a new Project Template for Telerik MVC Web Application. Let’s select that.</p>
<p><a href="http://mvcdotnet.files.wordpress.com/2012/07/image1.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://mvcdotnet.files.wordpress.com/2012/07/image_thumb1.png?w=295&#038;h=139" alt="image" width="295" height="139" border="0" /></a></p>
<p>Go through the Telerik Project Configuration Wizard and select all the default options. This will create the project and preconfigure all the necessary settings needed by the extensions. This includes configuration options in the web.config file and referencing JavaScript and css files.</p>
<p>After this let’s go ahead and install LinqToCsv. Right click on the references folder and select “Manage NuGet Packages” then search for “LinqToCsv” and install it.</p>
<p><a href="http://mvcdotnet.files.wordpress.com/2012/07/image2.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://mvcdotnet.files.wordpress.com/2012/07/image_thumb2.png?w=391&#038;h=104" alt="image" width="391" height="104" border="0" /></a></p>
<ul>We need to define a sample csv file. Let’s add a new file called people.csv to our desktop with the following data:</ul>
<blockquote><p>FirstName,LastName,Age,State<br />
John, Smith, 35, CA<br />
Mike, Jones, 29, AZ<br />
Susan, Baldwin, 45, CA<br />
Alex, Johnson, 32, WA</p></blockquote>
<p>As you can see, it’s a simple comma delimited file that represents people and includes their first name, last name , age and state.</p>
<p>We also need a class to represent this data. Let’s add a Person class to our models folder. Add a new class and name file Person.cs The contents of the file should look like this</p>
<pre class="code"><span style="color:blue;">public class </span><span style="color:#2b91af;">Person</span>{
    <span style="color:blue;">public string </span>FirstName { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
    <span style="color:blue;">public string </span>LastName { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
    <span style="color:blue;">public int </span>Age { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
    <span style="color:blue;">public string </span>State { <span style="color:blue;">get</span>; <span style="color:blue;">set</span>; }
}</pre>
<p>Now let’s modify the home controllers Index view to include a form an a file upload html control. Replace the contents of the file “Index.cshtml” in the Views/Home folder with the following:</p>
<blockquote><p><span style="background:yellow;">@{</span></p>
<p>ViewBag.Title = <span style="color:#a31515;">&#8220;Home Page&#8221;</span>;</p>
<p><span style="background:yellow;">}</span></p>
<p>@<span style="color:blue;">using </span>(Html.BeginForm(<span style="color:#a31515;">&#8220;Index&#8221;</span>, <span style="color:#a31515;">&#8220;Home&#8221;</span>, FormMethod.Post, <span style="color:blue;">new </span>{ enctype = <span style="color:#a31515;">&#8220;multipart/form-data&#8221; </span>}))</p>
<p>{</p>
<p><span style="color:blue;">&#60;</span><span style="color:maroon;">input </span><span style="color:red;">type</span><span style="color:blue;">=&#8221;file&#8221; </span><span style="color:red;">name</span><span style="color:blue;">=&#8221;file&#8221; /&#62;</span></p>
<p>&#60;<span style="color:maroon;">input </span><span style="color:red;">type</span><span style="color:blue;">=&#8221;submit&#8221; </span><span style="color:red;">name</span><span style="color:blue;">=&#8221;btnSubmit&#8221; </span><span style="color:red;">value</span><span style="color:blue;">=&#8221;Upload!&#8221;/&#62;</span></p>
<p>}</p></blockquote>
<p>Now let’s add some code to the controller so that we can save this file to disk. Let’s replace the action methods in HomeController.cs with the following two action methods:</p>
<blockquote><p><span style="color:blue;">public </span><span style="color:#2b91af;">ActionResult </span>Index(){</p>
<p><span style="color:blue;">return </span>View();</p>
<p>}</p>
<p>[<span style="color:#2b91af;">HttpPost</span>]</p>
<p><span style="color:blue;">public </span><span style="color:#2b91af;">ActionResult </span>Index(<span style="color:#2b91af;">HttpPostedFileBase </span>file){<br />
<span style="color:blue;">if </span>(file.ContentLength &#62; 0){</p>
<p><span style="color:blue;">var </span>fileName = <span style="color:#2b91af;">Path</span>.GetFileName(file.FileName);</p>
<p><span style="color:blue;">var </span>path = <span style="color:#2b91af;">Path</span>.Combine(Server.MapPath(<span style="color:#a31515;">&#8220;~/App_Data/&#8221;</span>), fileName);</p>
<p>file.SaveAs(path);</p>
<p>TempData[<span style="color:#a31515;">"file"</span>] = path;</p>
<p>}</p>
<p><span style="color:blue;">return </span>RedirectToAction(<span style="color:#a31515;">&#8220;Grid&#8221;</span>);</p>
<p>}</p></blockquote>
<p>Here we’ve added a second Index action method that takes in an HttpPostFileBase, this object will hold the reference to the uploaded file. Now it’s important to note that the name of the input parameter (“file” in our case) has to match up with the name of the html control. If the names don’t match up, the input parameter will come through as null.</p>
<p>In the action method we copy the file to the App_Data folder then we save the file path in TempData and redirect to a new Action called Grid.</p>
<p>The Grid action method will be responsible for reading data from the csv file and passing it to the view so that it can be rendered in telerik grid.</p>
<p>Add the following using statements to the top of your HomeController class</p>
<pre class="code"><span style="color:blue;">using </span>CsvToGrid.Models;
<span style="color:blue;">using </span>LINQtoCSV;</pre>
<p>Now add the Grid action method to the home controller.</p>
<pre class="code"><span style="color:blue;">public </span><span style="color:#2b91af;">ActionResult </span>Grid()
 {
     <span style="color:blue;">string </span>file = TempData[<span style="color:#a31515;">"file"</span>] <span style="color:blue;">as string</span>;
     <span style="color:blue;">if </span>(file == <span style="color:blue;">null</span>)
     {
         <span style="color:blue;">return </span>RedirectToAction(<span style="color:#a31515;">"Index"</span>);
     }

     <span style="color:#2b91af;">CsvContext </span>cc = <span style="color:blue;">new </span><span style="color:#2b91af;">CsvContext</span>();
     <span style="color:#2b91af;">List</span>&#60;<span style="color:#2b91af;">Person</span>&#62; people = cc.Read&#60;<span style="color:#2b91af;">Person</span>&#62;(file).ToList();

     <span style="color:blue;">return </span><span style="color:red;">View</span>(people);

 }</pre>
<p>This action method reads the file path from tempdata, then uses LinqToCSV to convert the data in the file to a collection of “Person”. This data I then returned to the view.</p>
<p>In the view we need to show this data as a Telerik Grid. Let’s define the view as a strongly typed view of type List&#60;Person&#62;. Let’s also add the code for the Telerik Grid. The complete view code should be</p>
<pre class="code"><span style="background:yellow;">@</span>model IEnumerable<span style="color:blue;">&#60;</span><span style="color:maroon;">CsvToGrid.Models.Person</span><span style="color:blue;">&#62;

</span><span style="background:yellow;">@{
</span>    ViewBag.Title = <span style="color:#a31515;">"Grid"</span>;
<span style="background:yellow;">}

</span><span style="color:blue;">&#60;</span><span style="color:maroon;">h2</span><span style="color:blue;">&#62;</span>Grid<span style="color:blue;">&#60;/</span><span style="color:maroon;">h2</span><span style="color:blue;">&#62;

</span><span style="background:yellow;">@(</span>Html.Telerik().Grid(Model).Name(<span style="color:#a31515;">"PeopleGrid"</span>)<span style="background:yellow;">)
</span></pre>
<p>Run the application by pressing alt-F5. On the home screen select the csv file we created earlier and click the upload button. The data within the csv file should now appear as data in your telerik mvc grid.</p>
<p><a href="http://mvcdotnet.files.wordpress.com/2012/07/image3.png"><img style="background-image:none;padding-left:0;padding-right:0;display:inline;padding-top:0;border:0;" title="image" src="http://mvcdotnet.files.wordpress.com/2012/07/image_thumb3.png?w=578&#038;h=133" alt="image" width="578" height="133" border="0" /></a></p>
<p>In part two of this post I’m going to show you how to customize the application so that you deal with csv data that doesn’t include a header row. You can download the complete source code for this <a href="www.hattanshobokshi.com/content/blog/csvtogrid.zip">demo site here</a>.</p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[AsyncUI MVC with Progressive Enhancement]]></title>
<link>http://candordeveloper.com/2012/07/19/asyncui-mvc-with-progressive-enhancement/</link>
<pubDate>Fri, 20 Jul 2012 04:01:46 +0000</pubDate>
<dc:creator>mlang74</dc:creator>
<guid>http://candordeveloper.com/2012/07/19/asyncui-mvc-with-progressive-enhancement/</guid>
<description><![CDATA[The top concerns for any site are having basic functionality, having it perform as fast as possible,]]></description>
<content:encoded><![CDATA[<p>The top concerns for any site are having basic functionality, having it perform as fast as possible, and then working for as many customer browsers as possible. Asynchronous User Interfaces are the latest technology to achieve the ultimate in performance.</p>
<p><a href="http://alexmaccaw.com/posts/async_ui">Alex Maccaw</a>:</p>
<blockquote><p>Web developers are still stuck in the request/response mindset. I call it the &#8216;click and wait&#8217; approach &#8211; where every UI interaction results in a delay before another interaction can be performed. [...]  developers still insist on using the request/response model. Even the introduction of Ajax hasn&#8217;t improved the scene much, replacing blank loading states with spinners. [...]</p>
<p>I&#8217;ve been working on this problem, specifically with a MVC JavaScript framework called <a href="http://spinejs.com/">Spine</a>, and implementing what I&#8217;ve dubbed <em>asynchronous user interfaces</em>, or AUIs. The key to this is that interfaces should be <strong>completely non-blocking</strong>. Interactions should be resolved instantly; there should be no loading messages or spinners. Requests to the server should be decoupled from the interface.</p></blockquote>
<p>I am using different technology to solving the problem than Alex, but the end result is the same.  My approach focuses on using Microsoft Asp.Net MVC, jQuery, and a custom javascript library I created.  This technique let&#8217;s me focus on building HTML with attributes and then the script automatically enhances those views to interact with my MVC controller action methods.</p>
<h2>Final Output</h2>
<p>Here is a screenshot of the final profile page for which I will show how to implement the email section.  There are 9 different areas in which you can edit something on the page, including your sign in credentials, real name, birthdate, a markdown editor for a bio, an email address, a phone number, an address, a phone number, and a school/job section.  In loading this entire page the initial load time is only 1/2 a second, plus another 4/5 second for images from another domain.  I&#8217;ll cut that down after I add bundling and more minification of the resources.</p>
<p><a href="http://candordeveloper.files.wordpress.com/2012/07/profile-main-load.png?w=1024"><img class="alignnone  wp-image-166" title="Profile Main page load with timings" src="http://candordeveloper.files.wordpress.com/2012/07/profile-main-load.png?w=1024&#038;h=821" alt="" width="1024" height="821" /></a></p>
<p>As the following screenshot shows the Undo Delete only takes 58 milliseconds post time.  But before the post began the view had already toggled to the readonly version.  I don&#8217;t know of any tools to track how long javascript ran before the post began, but to me using the button it felt instantaneous.  All the buttons feel just as fast using the code shown in this article.</p>
<p><a href="http://candordeveloper.files.wordpress.com/2012/07/profile-undo-delete-perf.png?w=1024"><img class="alignnone  wp-image-168" title="profile-undo-delete-perf" src="http://candordeveloper.files.wordpress.com/2012/07/profile-undo-delete-perf.png?w=1024&#038;h=403" alt="Profile Undo Delete performance" width="1024" height="403" /></a></p>
<h2>MVC Adaptive Controller</h2>
<p>To support progressive enhancement you will need to support users that do not have AJAX support or that have limited support.  It is easy to make a controller action return either JSON data for consumption by javascript and to support returning view HTML.  Here are some simple controller actions that returns a profile email address for a user as either an HTML view or as JSON.</p>
<pre class="brush: csharp; title: ; notranslate" title=""> //UserProfileController.cs
public virtual ActionResult EmailList( Guid userID )
{
	UserProfileEmailListViewModel model = new UserProfileEmailListViewModel();
	model.Load(userID);
	if (this.IsJsonRequest())
		return Json(model, JsonRequestBehavior.AllowGet);
	else
		return View(MVC.UserProfile.Views.EmailList, model);
}
public virtual ActionResult EmailView( Guid userID, long id )
{
	UserProfileEmailViewModel model = new UserProfileEmailViewModel() { UserID = userID };
	UserProfileEmail item = UserProfileManager.GetUserProfileEmail(userID, id, model.Results);
	model.Load(item);
	if (this.IsJsonRequest())
		return Json(model, JsonRequestBehavior.AllowGet);
	else
		return View(MVC.UserProfile.Views.EmailView, model);
}
public virtual ActionResult EmailEdit( Guid userID, long id )
{
	UserProfileEmailViewModel model = new UserProfileEmailViewModel() { UserID = userID };
	UserProfileEmail item = UserProfileManager.GetUserProfileEmail(userID, id, model.Results);
	model.Load(item);
	if (this.IsJsonRequest())
		return Json(model, JsonRequestBehavior.AllowGet);
	else
		return View(MVC.UserProfile.Views.EmailEdit, model);
} //UserProfileController.cs</pre>
<p>The key in adapting your result to what is requested is to check if the request is for JSON. You can support this by adding a simple Controller class extension method somewhere in your project or in a shared library.</p>
<pre class="brush: csharp; title: ; notranslate" title="">public static class ControllerExtensions
{
	public static bool IsJsonRequest( this Controller controller )
	{
		foreach (string a in controller.Request.AcceptTypes)
			if (a.ToLower().Contains(&#34;json&#34;))
				return true;
		return false;
	}
	public static bool IsAjaxRequest( this Controller controller )
	{
		return controller.Request.IsAjaxRequest();
	}
}</pre>
<p>The create action method is slightly different in that it needs to potentially return a success flag or possibly error messages.  In the case of create and delete these action methods will rarely, if ever, be called in the case when the browser supports AJAX.  So these action methods support both JSON and the normal get HTML options, but they are primarily for the latter.</p>
<pre class="brush: csharp; title: ; notranslate" title=""> //UserProfileController.cs
public virtual ActionResult EmailCreate( Guid userID )
{
	UserProfileEmailViewModel model = new UserProfileEmailViewModel();
	model.UserID = userID;
	if (this.IsJsonRequest())
		return Json(new { success = true, item = model }, JsonRequestBehavior.AllowGet);
	else //99% case
		return View(MVC.UserProfile.Views.EmailEdit, model);
}
public virtual ActionResult EmailDelete( Guid userID, long id )
{
	UserProfileEmailViewModel model = new UserProfileEmailViewModel() { UserID = userID };
	UserProfileEmail item = UserProfileManager.GetUserProfileEmail(userID, id, model.Results);
	model.Load(item);
	if (this.IsJsonRequest())
		return Json(model, JsonRequestBehavior.AllowGet);
	else
		return View(MVC.UserProfile.Views.EmailDelete, model);
} //UserProfileController.cs</pre>
<p style="padding-left:30px;">All of these methods are using a class called UserProfileManager to get data.  In case you are wondering how that business layer works, you can read my previous articles on <a href="http://candordeveloper.com/2012/07/05/provider-model-layered-architecture/">provider model</a>.  It really isn&#8217;t pertinent to this article so I won&#8217;t mention it in this article again.</p>
<h3>MVC Post Action Methods</h3>
<p>When doing a post for create, edit, or delete you may be responding to an AJAX request from the AsyncUI javascript or it may be a full browser request from a client that does not support AJAX properly. In the AsycnUI case you want to return a message, if applicable, and then let the calling page determine if the user stays on the page or needs to go elsewhere. In the form post method, the client was likely just on a full edit page since they don&#8217;t support AJAX and AsyncUI, so on success you want to redirect them back to the page from before the edit. Or in the failure case (with no AsyncUI) you want to keep them on the edit page and show the error message. To support these different result options, I create helper methods in the controller to determine the correct ActionResult.</p>
<pre class="brush: csharp; title: ; notranslate" title=""> //UserProfileController.cs
private ActionResult UserProfileEmailResult( UserProfileEmailViewModel model, ExecutionResults result )
{
	model.Results = result;
	if (this.IsAjaxRequest()) //99% case
		return Json(new { success = result.Success, message = result.ToHtmlString(), item = model }); //passing item back because it can change - share description is calculated
	else if (result.Success)
		return RedirectToAction(MVC.UserProfile.Main(SecurityContext.CurrentIdentity.Name));
	else
		return View(MVC.UserProfile.Views.EmailEdit, model);
}
private ActionResult CancelResult()
{
	if (this.IsAjaxRequest()) //1% case - cancel was not enhanced properly to revert to view mode on client side.
		return Json(new { success = true });
	else
		return RedirectToAction(MVC.UserProfile.Main(SecurityContext.CurrentIdentity.Name));
} // //UserProfileController.cs.  Note, The code here is using T4MVC to generate urls.</pre>
<p>I can now leverage this in the save, delete, and undo delete operations.  The XCancel action methods will not typically be invoked for most users.  But these methods are here for the case when javascript is disabled and the button needs to cause a navigation somewhere.  You can accomplish this by setting urls on cancel links instead of having cancel behave like a button.  But I included the XCancel action methods because I wanted to demonstrate the FormPostActionSelector attribute also.</p>
<pre class="brush: csharp; title: ; notranslate" title="">//UserProfileController.cs
[AcceptVerbs(HttpVerbs.Post)]
[FormPostActionSelector(ButtonName = &#34;Save&#34;)]
public virtual ActionResult EmailEditSave( UserProfileEmailViewModel model )
{
	ExecutionResults result = new ExecutionResults();
	if (SecurityContext.CurrentUser.IsAnonymous)
	{
		result.AppendError(&#34;You must be logged in to save this.&#34;);
		return UserProfileEmailResult(model, result);
	}
	model.UserID = SecurityContext.CurrentIdentity.ID;
	UserProfileEmail item = null;
	if (model.ID != -1 &#38;amp;&#38;amp; model.ID != 0)
		item = UserProfileManager.GetUserProfileEmail(model.UserID, model.ID, result);
	if (item == null)
		item = new UserProfileEmail() { UserID = model.UserID };
	if (!result.Success)
		return UserProfileEmailResult(model, result);
	item.EmailType = model.EmailType ?? string.Empty;
	item.Address = model.Address ?? string.Empty;
	item.IsPrimaryNotification = model.IsPrimaryNotification;
	item.Groups = model.Groups ?? string.Empty;
	item.Comments = model.Comments ?? string.Empty;
	item.SuggestContacts = model.SuggestContacts;
	UserProfileManager.SaveUserProfileEmail(item, result); //method populates 'result' with any validation errors
	model.Load(item);
	return UserProfileEmailResult(model, result);
}
[AcceptVerbs(HttpVerbs.Post)]
[FormPostActionSelector(ButtonName = &#34;Cancel&#34;)]
public virtual ActionResult EmailEditCancel( UserProfileEmailViewModel model )
{
	return CancelResult();
}
[AcceptVerbs(HttpVerbs.Post)]
public virtual ActionResult EmailDeleteConfirm( Guid userID, long id )
{
	ExecutionResults result = new ExecutionResults();
	if (SecurityContext.CurrentUser.IsAnonymous)
	{
		result.AppendError(&#34;You must be logged in to delete this.&#34;);
		return UserProfileEmailResult(new UserProfileEmailViewModel() { UserID = userID, ID = id }, result);
	} 

	UserProfileEmail item = UserProfileManager.GetUserProfileEmail(userID, id, result);
	UserProfileEmailViewModel model = new UserProfileEmailViewModel();
	UserProfileManager.DeleteUserProfileEmail(item, result);
	model.Load(item);
	return UserProfileEmailResult(model, result);
}
[AcceptVerbs(HttpVerbs.Post)]
[FormPostActionSelector(ButtonName = &#34;Cancel&#34;)]
public virtual ActionResult EmailDeleteConfirmCancel( Guid userID, long id )
{
	return CancelResult();
}
[AcceptVerbs(HttpVerbs.Post)]
public virtual ActionResult EmailDeleteUndo( Guid userID, long id )
{
	ExecutionResults result = new ExecutionResults();
	if (SecurityContext.CurrentUser.IsAnonymous)
	{
		result.AppendError(&#34;You must be logged in.&#34;);
		return UserProfileEmailResult(new UserProfileEmailViewModel() { UserID = userID, ID = id }, result);
	}
	UserProfileEmail item = UserProfileManager.GetUserProfileEmail(userID, id, result);
	UserProfileEmailViewModel model = new UserProfileEmailViewModel();
	item.IsDeleted = false;
	UserProfileManager.SaveUserProfileEmail(item, result);
	model.Load(item);
	return UserProfileEmailResult(model, result);
}//UserProfileController.cs</pre>
<h3>FormPostActionSelector</h3>
<p>Some of the code above used a custom <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.actionnameselectorattribute.aspx">action name selector</a> called FormPostActionSelector. This lets you just put a button on a form in your view and then let the controller action method intercept which button it handles. If you only have one button (like Save), then this is not necassary. But if you have two or more buttons on a form then it let&#8217;s you have a post action for each of the form&#8217;s buttons. I have this in a <a href="https://github.com/michael-lang/candor-common/tree/master/Candor.Web.Mvc">shared library</a> and it is available within <a href="http://nuget.org/packages/Candor.Web.Mvc/">NuGet package candor.web.mvc</a>.</p>
<pre class="brush: csharp; title: ; notranslate" title="">using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace XQuiSoft.Xulgent.MvcWebApplication.Filters
{
	/// &#60;summary&#62;
	/// Matches a controller action method to a post from another action where the attributed action is the name of a button on the form.
	/// &#60;/summary&#62;
	/// &#60;remarks&#62;
	/// Variation from source article: http://blog.ashmind.com/2010/03/15/multiple-submit-buttons-with-asp-net-mvc-final-solution/
	/// &#60;/remarks&#62;
	public class FormPostActionSelectorAttribute : ActionNameSelectorAttribute
	{
		/// &#60;summary&#62;
		/// Gets or sets the name of the action method that must match.  
		/// Or leave empty to match on a combination of the method name 
		/// and button name.
		/// &#60;/summary&#62;
		public string FormActionName { get; set; }
		/// &#60;summary&#62;
		/// Gets or sets the name of the button (form field name) that
		/// must post in order to match the action method.
		/// &#60;/summary&#62;
		public string ButtonName { get; set; }
		/// &#60;summary&#62;
		/// Creates a new instance.
		/// &#60;/summary&#62;
		public FormPostActionSelectorAttribute() : base() { }
		/// &#60;summary&#62;
		/// Determines if the current request matches this method.
		/// &#60;/summary&#62;
		/// &#60;param name=&#34;controllerContext&#34;&#62;&#60;/param&#62;
		/// &#60;param name=&#34;actionName&#34;&#62;&#60;/param&#62;
		/// &#60;param name=&#34;methodInfo&#34;&#62;&#60;/param&#62;
		/// &#60;returns&#62;&#60;/returns&#62;
		public override bool IsValidName( ControllerContext controllerContext, 
			string actionName, System.Reflection.MethodInfo methodInfo )
		{
			if (!string.IsNullOrEmpty(ButtonName))
			{
				if (controllerContext.RequestContext.HttpContext.Request[ButtonName] != ButtonName)
					return false;
				if (!string.IsNullOrEmpty(FormActionName))
				{
					if (actionName == FormActionName &#38;amp;&#38;amp; actionName.Equals(methodInfo.Name, StringComparison.InvariantCultureIgnoreCase))
						return true;

					if (methodInfo.Name == ButtonName &#38;amp;&#38;amp; actionName == FormActionName)
						return true;
					else
						return false;
				}
				else if (ButtonName.StartsWith(actionName))
					return methodInfo.Name == ButtonName &#124;&#124; methodInfo.Name == actionName + ButtonName;
				else
					return methodInfo.Name == actionName + ButtonName;
			}
			else if (!string.IsNullOrEmpty(FormActionName))
			{
				if (actionName.Equals(methodInfo.Name, StringComparison.InvariantCultureIgnoreCase))
					return true;

				if (!actionName.Equals(FormActionName, StringComparison.InvariantCultureIgnoreCase))
					return false;

				return controllerContext.RequestContext.HttpContext.Request[methodInfo.Name] != null;
			}
			return false;
		}
	}
}</pre>
<h2>Asp.Net MVC View Models</h2>
<p>Something to consider when creating a view model class that is used as both a means to bind a view and to return as JSON is that you may need more values in your view file than you want serialized as part of your JSON data.  You can accomplish property hiding in your JSON data with the ScriptIgnoreAttribute.  For instance, I have a model class that I use for an email address that has a property with business layer validation messages on it.  I use it on the server side view to render a validation block.  But in the client side view template I don&#8217;t use that mechanism for returning error messages since the server side property holding those messages is bloated when serialized to JSON. Another thing you&#8217;ll notice about the controller method above is the Load method. This is just my personal preference that the view model knows how to load itself from the core business objects that it represents. You could just as easily put that Load logic in your controller. I prefer it in a Load method so that if I ever reuse my view model elsewhere in the controller or in other controllers I only have to maintain that mapping logic in one place.</p>
<pre class="brush: csharp; title: ; notranslate" title="">	public class UserProfileEmailViewModel
	{
		public UserProfileEmailViewModel()
		{
			Results = new ExecutionResults();
		}

		[ScriptIgnore]
		public ExecutionResults Results { get; set; }
		public long ID { get; set; }
		public Guid UserID { get; set; }
		[DisplayName(&#34;Type&#34;)]
		public string EmailType { get; set; }
		[DisplayName(&#34;Email&#34;)]
		public string Address { get; set; }
		public bool IsValidated { get; set; }
		[DisplayName(&#34;Receive notifications at this email address&#34;)]
		public bool IsPrimaryNotification { get; set; }
		public bool IsDeleteable { get; set; }
		[DisplayName(&#34;Share With&#34;)]
		public string Groups { get; set; }
		public bool IsDeleted { get; set; }
		[DisplayName(&#34;Notes&#34;)]
		public string Comments { get; set; }
		[DisplayName(&#34;Let others find me by this email address&#34;)]
		public bool SuggestContacts { get; set; }
		public string ShareDescription
		{
			get
			{
				if (UserID.Equals(SecurityContext.CurrentIdentity.ID))
					return SharingManager.GetUserVisibilityDescription(UserID, Groups);
				else
					return SharingManager.GetPublicVisibilityDescription(UserID, Groups);
			}
		}
		public bool IsViewingUser
		{
			get { return UserID.Equals(SecurityContext.CurrentUser.Identity.ID); }
		}

		public void Load(UserProfileEmail source)
		{
			if (source != null)
			{
				ID = source.ID;
				UserID = source.UserID;
				EmailType = string.IsNullOrWhiteSpace(source.EmailType) ? null : source.EmailType; //want null on view model for empty value - useful in JSON payload as null
				Address = source.Address;
				IsValidated = source.IsValidated;
				IsPrimaryNotification = source.IsPrimaryNotification;
				IsDeleteable = !source.IsValidated &#124;&#124; !source.IsPrimaryNotification;
				Groups = IsViewingUser ? source.Groups : &#34;&#34;;
				IsDeleted = source.IsDeleted;
				Comments = string.IsNullOrWhiteSpace(source.Comments) ? null : source.Comments; //want null on view model for empty value - useful in JSON payload as null
				SuggestContacts = source.SuggestContacts;
			}
		}
	}</pre>
<h2>Asp.Net MVC Razor Views</h2>
<h3>&#8216;EmailList&#8217; Razor View</h3>
<p>On my profile page where I want a list of email addresses that are editable I just render a partial of my email list. First the view code, then I&#8217;ll explain it.</p>
<pre class="brush: xml; title: ; notranslate" title="">@model XQuiSoft.Xulgent.MvcWebApplication.Models.UserProfile.UserProfileEmailListViewModel
&#60;div id=&#34;user-profile-email-list&#34; class=&#34;user-profile-email-list inline-editable-host&#34; @if (Model.IsViewingUser){ &#60;text&#62;
	data-json-url=&#34;@Url.Action(MVC.UserProfile.EmailList(Model.UserID))&#34;
	data-json-var=&#34;UserProfileEmailListJSON&#34;
	data-template=&#34;UserProfileEmailView&#34; &#60;/text&#62;}&#62;
	@foreach (var item in Model.Items)
	{
		Html.RenderPartial(MVC.UserProfile.Views.EmailView, item);
	}
&#60;/div&#62;
@if (Model.IsViewingUser)
{
&#60;script id=&#34;UserProfileEmailListJSON&#34; type=&#34;text/javascript&#34;&#62;
	var UserProfileEmailListJSON = @Html.Raw(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(Model))
&#60;/script&#62;
&#60;script id=&#34;UserProfileEmailEdit&#34; type=&#34;text/x-jQuery-tmpl&#34;&#62;
	@{Html.RenderPartial(MVC.UserProfile.Views.EmailEditTemplate, Model);}
&#60;/script&#62;	
&#60;script id=&#34;UserProfileEmailView&#34; type=&#34;text/x-jQuery-tmpl&#34;&#62;
	@{Html.RenderPartial(MVC.UserProfile.Views.EmailViewTemplate, Model);}
&#60;/script&#62;
&#60;script id=&#34;UserProfileEmailDeleteUndo&#34; type=&#34;text/x-jQuery-tmpl&#34;&#62;
	@{Html.RenderPartial(MVC.UserProfile.Views.EmailDeleteUndoTemplate, Model);}
&#60;/script&#62;
}</pre>
<p>This particular view can only be used server side to render the initial list, as you can see with the @model declaration on the first line. There is no client side template for the list as a whole. That isn&#8217;t to say you couldn&#8217;t do that, but I choose not to for my project. In the next lines notice how a bunch of data attributes are only output if the current viewing user is the owner of the profile. These attributes support the editing, so there is no point in putting them on the page for a visitor of the profile. There is also a section below that defines the client side templates, and it is only output for the owner of the profile.</p>
<p>For the owner of the profile we are also outputting a javascript variable populated with the initial JSON data used to populate the list. However, in the section above you also see the initial view templates are output. The view template is rendered out on the server side initially so that something appears before any javascript runs. This is important for progressive enhancement, which then supports both users without javascript enabled and for search engines. So why output the JSON data? This is to make a second pass at these elements to make them editable via AsyncUI. But you don&#8217;t have to output the JSON as a variable. You can just load the JSON after the page loads via AJAX. The data attributes in this view support both options.</p>
<h3>Data Attributes</h3>
<ul>
<li><strong>data-json-url</strong>. This option let&#8217;s you define the url where the JSON will be loaded for the list.</li>
<li><strong>data-json-var</strong>. This lets you define the name of the (global scope) variable holding the JSON for this list. This option does pollute your global scope, so the data-json-url option may be preferred for the idealistic approach. However, the variable option is faster given that another request to the server via AJAX is not needed to prep the list items for edit.</li>
<li><strong>data-template</strong>. This is the initial template name to use for the initial rendering of each JSON object in the list defined in one of the previous options. You should typically set this to the name of your view template. But if you want all your items shown as editable on page load, you can put that template name here instead.</li>
</ul>
<h3>&#8216;EmailView&#8217; Razor view</h3>
<p>As you can see on the list I render out the initial view of each item on the server side. So I need a Razor view for just viewing the data. This code is standard server side MVC Razor. The only thing special about it is that there is a class on the top level element called &#8216;inline-editable&#8217; that the javascript library looks for.</p>
<pre class="brush: xml; title: ; notranslate" title="">@model XQuiSoft.Xulgent.MvcWebApplication.Models.UserProfile.UserProfileEmailViewModel
@if (!Model.IsDeleted)
{ // deleted items are only shown via templates.  For users without javascript they will see a warning before delete instead of the undo delete.
&#60;span class=&#34;inline-editable user-profile-email&#34;&#62;
	@if(Model.IsViewingUser){ 
		if (Model.IsDeleteable){
	&#60;a href=&#34;@Url.Action(MVC.UserProfile.EmailDelete(Model.UserID, Model.ID))&#34; class=&#34;inline-editable-button ui-icon ui-icon-cancel&#34; title=&#34;click to delete&#34;
		data-url=&#34;@Url.Action(MVC.UserProfile.EmailDeleteConfirm())&#34; 
		data-template=&#34;UserProfileEmailDeleteUndo&#34;&#62;&#60;/a&#62;
		}
	&#60;a href=&#34;@Url.Action(MVC.UserProfile.EmailEdit(Model.UserID, Model.ID))&#34; class=&#34;inline-editable-button&#34; title=&#34;click to edit&#34; 
		data-template=&#34;UserProfileEmailEdit&#34; &#62;
		&#60;span class=&#34;ui-icon ui-icon-pencil&#34;&#62;&#60;/span&#62;
		&#60;span class=&#34;user-profile-email-address&#34;&#62;@Model.Address&#60;/span&#62;
	&#60;/a&#62;
	}
	else
	{
		&#60;span class=&#34;user-profile-email-address&#34;&#62;@Model.Address&#60;/span&#62;
	}
	@if (!string.IsNullOrEmpty(Model.EmailType))
	{ 
	&#60;span class=&#34;user-profile-item-type&#34;&#62;(@Model.EmailType)&#60;/span&#62;
	}
	@if(Model.IsViewingUser){ 
	&#60;span class=&#34;user-profile-item-share-description&#34;title=&#34;@Model.ShareDescription&#34;&#62;Visible to: @Model.Groups&#60;/span&#62;
	}
	@if (!string.IsNullOrEmpty(Model.Comments))
	{
	&#60;span class=&#34;user-profile-email-comment notice&#34;&#62;@Model.Comments&#60;/span&#62;
	}
&#60;/span&#62;
}</pre>
<p>This view has two buttons on it. The delete button posts a delete to the server immediately and then toggles to the delete undo view.  The edit button just toggles to the edit view and does not send anything to the server.  Edit, Delete, View, and Undo delete are NOT built in behaviors of the script.  You are just setting up those behaviors by the attributes you put on the buttons.  The script follows the same steps for the above as it does for the edit view buttons below.</p>
<h3>&#8216;EmailEditTemplate&#8217; view</h3>
<p>If the user wants to make an edit, we switch over to the edit template on the client side. This is without making a request back to the server. So this view switches practically immediately, or at least as fast as the javascript engine can make the rendering change. No latency or other server processing delay is involved. The only &#8216;server side&#8217; processed portion of rendering this view is at the time that the view is sent to the browser on the initial page request, which is just to build the form tag posting to the correct controller action, and building textarea and input tags. The data put in those inputs is done when the template is rendered.</p>
<pre class="brush: xml; title: ; notranslate" title="">&#60;span class=&#34;inline-editable user-profile-email&#34;&#62;
@using (Html.BeginForm(MVC.UserProfile.EmailEdit()))
{
	&#60;p class=&#34;notice&#34;&#62;
		Only enter email accounts under your control. Otherwise the owner of the email address
		could potentially compromise your account&#60;/p&#62;
	&#60;input type=&#34;hidden&#34; value=&#34;${ID}&#34; id=&#34;ID&#34; name=&#34;ID&#34; /&#62;
	&#60;input type=&#34;hidden&#34; value=&#34;${UserID}&#34; id=&#34;UserID&#34; name=&#34;UserID&#34; /&#62;
	&#60;div class=&#34;property&#34;&#62;
		&#60;label for=&#34;Address&#34;&#62;Email&#60;/label&#62;:
		@Html.TextBox(&#34;Address&#34;, &#34;${Address}&#34;, new { style = &#34;width:300px;&#34; })
		&#60;span class=&#34;input-tip&#34;&#62;Examples: alias@live.com, alias@gmail.com, alias@sample-company.com&#60;/span&#62;
	&#60;/div&#62;
	&#60;div class=&#34;property&#34;&#62;
		&#60;label for=&#34;EmailType&#34;&#62;Type&#60;/label&#62;:
		@Html.TextBox(&#34;EmailType&#34;, &#34;${EmailType}&#34;, new { @class = &#34;autocomplete&#34;, style = &#34;width:300px;&#34;, data_autocomplete_url = @Url.Action(MVC.ContactMethod.GetEmailTypes()), data_autocomplete_delay = 600 })
		&#60;span class=&#34;input-tip&#34;&#62;The type of email address (Personal, Work, or add a new one)&#60;/span&#62;
	&#60;/div&#62;
	&#60;div class=&#34;property&#34;&#62;
		&#60;label for=&#34;Groups&#34;&#62;Share With&#60;/label&#62;:
		@Html.TextBox(&#34;Groups&#34;, &#34;${Groups}&#34;, new { @class = &#34;group-listbuilder listbuilder&#34;, style = &#34;width:300px;&#34;, data_autocomplete_url = @Url.Action(MVC.Sharing.FindPermissableGroups()), data_autocomplete_itemtemplate = &#34;PermissableMemberSummary&#34; })
		&#60;span class=&#34;input-tip&#34;&#62;Enter 'family', 'friends', 'coworkers', or any custom group
			name such as 'college friends' or 'neighbors'. Hit enter after each group name you
			type or click on one from the list. &#60;/span&#62;
	&#60;/div&#62;
	&#60;div class=&#34;property&#34;&#62;
		&#60;input type=&#34;checkbox&#34; value=&#34;true&#34; name=&#34;SuggestContacts&#34; id=&#34;SuggestContacts&#34; @Html.Raw(&#34;{{if SuggestContacts}}checked{{/if}}&#34;) /&#62;
		&#60;input type=&#34;hidden&#34; value=&#34;false&#34; name=&#34;SuggestContacts&#34;/&#62;
		&#60;label for=&#34;SuggestContacts&#34;&#62;Let others find me by this email address&#60;/label&#62;
	&#60;/div&#62;
	&#60;div class=&#34;property&#34;&#62;
		&#60;input type=&#34;checkbox&#34; value=&#34;true&#34; name=&#34;IsPrimaryNotification&#34; id=&#34;IsPrimaryNotification&#34; @Html.Raw(&#34;{{if IsPrimaryNotification}}checked{{/if}}&#34;) /&#62;
		&#60;input type=&#34;hidden&#34; value=&#34;false&#34; name=&#34;IsPrimaryNotification&#34;/&#62;
		&#60;label for=&#34;IsPrimaryNotification&#34;&#62;Receive notifications at this email address&#60;/label&#62;
	&#60;/div&#62;
	&#60;div class=&#34;property&#34;&#62;
		&#60;label for=&#34;Comments&#34;&#62;Notes&#60;/label&#62;:
		&#60;textarea class=&#34;resizable&#34; cols=&#34;20&#34; id=&#34;Comments&#34; name=&#34;Comments&#34; rows=&#34;2&#34; style=&#34;width:425px;&#34;&#62;${Comments}&#60;/textarea&#62;
		&#60;span class=&#34;input-tip&#34; style=&#34;width: 400px;&#34;&#62;An explanation of when those that you
			share the address with should use it.&#60;/span&#62;
	&#60;/div&#62;
	&#60;div class=&#34;&#34;&#62;
		&#60;input type=&#34;submit&#34; value=&#34;Save&#34; id=&#34;Save&#34; name=&#34;Save&#34; class=&#34;inline-editable-button link-button ui-state-default ui-corner-all link-button-confirm left-float&#34; 
			data-template=&#34;UserProfileEmailView&#34; /&#62;
		&#60;input type=&#34;submit&#34; value=&#34;Cancel&#34; id=&#34;Cancel&#34; name=&#34;Cancel&#34; class=&#34;inline-editable-button link-button ui-state-default ui-corner-all link-button-cancel right-float&#34;
			data-template=&#34;UserProfileEmailView&#34; data-url=&#34;&#34; /&#62;
		&#60;span class=&#34;msg clear&#34;&#62;&#60;/span&#62;
	&#60;/div&#62;
}
&#60;br /&#62;
&#60;/span&#62;</pre>
<p>Just like the previous view there is a class on the top level element called &#8216;inline-editable&#8217; that the javascript library looks for. Additionally since this view has buttons on it, it also has an attribute on each button called &#8220;data-template&#8221; which defines which view to toggle to when the button is pressed. But if the action posted to fails, the view is switched back to the edit view with any error messages from the server or updated values from the server automatically. A few of the other inputs also have special classes and data attributes on them so that they are progressively enhanced into jQuery controls after rendering of the template. I might discuss those in another article.  I won&#8217;t now since they as are not required for making AsyncUI work.</p>
<h3>&#8216;EmailEdit&#8217; View</h3>
<p>There is another view for email edit when the server needs to render it.  If you look back at the &#8216;EmailView&#8217; razor view you&#8217;ll see that the buttons have an href attribute.  These buttons are hyperlinks that are enhanced with the jQuery button widget to look like a button.  If script is disabled, when the user clicks on the button/link they will navigate to the edit view.  If script is enabled, the script changes the href to &#8220;#&#8221; and attached a click handler that does the steps mentioned above instead (AsyncUI).</p>
<p>When the edit view is shown as rendered by the server then we render it slightly differently and using Razor syntax instead of template syntax.</p>
<pre class="brush: xml; title: ; notranslate" title="">@model XQuiSoft.Xulgent.MvcWebApplication.Models.UserProfile.UserProfileEmailViewModel
&#60;span class=&#34;inline-editable user-profile-email&#34;&#62;
@using (Html.BeginForm(MVC.UserProfile.EmailEdit()))
{
	&#60;p class=&#34;notice&#34;&#62;
		Only enter email accounts under your control. Otherwise the owner of the email address
		could potentially compromise your account&#60;/p&#62;
	@Html.HiddenFor(model =&#62; model.ID)
	@Html.HiddenFor(model =&#62; model.UserID)
	&#60;div class=&#34;property&#34;&#62;
		@Html.LabelFor(model =&#62; model.Address):
		@Html.TextBoxFor(model =&#62; model.Address, new { style = &#34;width:300px;&#34; })
		&#60;span class=&#34;input-tip&#34;&#62;Examples: alias@live.com, alias@gmail.com, alias@sample-company.com&#60;/span&#62;
	&#60;/div&#62;
	&#60;div class=&#34;property&#34;&#62;
		@Html.LabelFor(model =&#62; model.EmailType):
		@Html.TextBoxFor(model =&#62; model.EmailType, new { @class = &#34;autocomplete&#34;, style = &#34;width:300px;&#34;, data_autocomplete_url = @Url.Action(MVC.ContactMethod.GetEmailTypes()), data_autocomplete_delay = 600 })
		&#60;span class=&#34;input-tip&#34;&#62;The type of email address (Personal, Work, or add a new one)&#60;/span&#62;
	&#60;/div&#62;
	&#60;div class=&#34;property&#34;&#62;
		@Html.LabelFor(model =&#62; model.Groups):
		@Html.TextBoxFor(model =&#62; model.Groups, new { @class = &#34;group-listbuilder listbuilder&#34;, style = &#34;width:300px;&#34;, data_autocomplete_url = @Url.Action(MVC.Sharing.FindPermissableGroups()), data_autocomplete_itemtemplate = &#34;&#60;strong&#62;${Name}&#60;/strong&#62;: ${ContactCount}:${MemberCount}&#60;/br&#62;&#60;em&#62;${MemberSummary}&#60;/em&#62;&#34; })
		&#60;span class=&#34;input-tip&#34;&#62;Enter 'family', 'friends', 'coworkers', or any custom group
			name such as 'college friends' or 'neighbors'. Hit enter after each group name you
			type or click on one from the list. &#60;/span&#62;
	&#60;/div&#62;
	&#60;div class=&#34;property&#34;&#62;
		@Html.CheckBoxFor(model =&#62; model.SuggestContacts)
		@Html.LabelFor(model =&#62; model.SuggestContacts)
	&#60;/div&#62;
	&#60;div class=&#34;property&#34;&#62;
		@Html.CheckBoxFor(model =&#62; model.IsPrimaryNotification)
		@Html.LabelFor(model =&#62; model.IsPrimaryNotification)
	&#60;/div&#62;
	&#60;div class=&#34;property&#34;&#62;
		@Html.LabelFor(model =&#62; model.Comments):
		@Html.TextAreaFor(model =&#62; model.Comments, new { @class = &#34;resizable&#34;, style = &#34;width:425px;&#34; })
		&#60;span class=&#34;input-tip&#34; style=&#34;width: 400px;&#34;&#62;An explanation of when those that you
			share the address with should use it.&#60;/span&#62;
	&#60;/div&#62;
	&#60;div class=&#34;&#34;&#62;
		&#60;input type=&#34;submit&#34; value=&#34;Save&#34; id=&#34;Save&#34; name=&#34;Save&#34; class=&#34;link-button ui-state-default ui-corner-all link-button-confirm left-float&#34; /&#62;
		&#60;input type=&#34;submit&#34; value=&#34;Cancel&#34; id=&#34;Cancel&#34; name=&#34;Cancel&#34; class=&#34;link-button ui-state-default ui-corner-all link-button-cancel right-float&#34; /&#62;
		@Html.DisplayFor(model =&#62; model.Results)
		&#60;span class=&#34;msg clear&#34;&#62;&#60;/span&#62;
	&#60;/div&#62;
}
&#60;/span&#62;</pre>
<p>Notice this edit view does not have the data attributes. If this view is shown we already know script is disabled on the client so the data attributes are not needed. The buttons on this edit view post directly to the MVC controller  EmailEditSave action method synchronously.  So we fallback to the &#8216;click and wait&#8217; model when script is disabled.  Look back at the UserProfileEmailResult and this is where the RedirectToAction occurs on a succesful edit, and on a failed edit the EmailEdit view is returned again with the values that were just posted.</p>
<h3>&#8216;EmailViewTemplate&#8217; view</h3>
<p>After a user completes editing an item and they cancel or save, we need to toggle back over to the edit view.  This toggle should be immediate using a template and with the data on the form (in the save case).  We can&#8217;t use the &#8216;EmailView&#8217; view because that is a server side rendering.  This template initially is rendered on the server as part of the &#8216;EmailList&#8217; view.  This is why all the @Html.Raw Razor syntax blocks are in the file.  But that is just to get the template to the client.  Once on the client those do not exist are are not part of the rendering of the template client side.  Html.Raw is needed because otherwise the file would not be valid Razor syntax.</p>
<pre class="brush: xml; title: ; notranslate" title="">@Html.Raw(&#34;{{if IsDeleted}}&#34;) 
@Html.Raw(&#34;{{tmpl '#UserProfileEmailDeleteUndo'}}&#34;)
@Html.Raw(&#34;{{else}}&#34;)
&#60;span class=&#34;inline-editable user-profile-email&#34;&#62;
	@Html.Raw(&#34;{{if IsViewingUser}}&#34;)
	@Html.Raw(&#34;{{if IsDeleteable}}&#34;) 
	&#60;a href=&#34;#&#34; class=&#34;inline-editable-button ui-icon ui-icon-cancel&#34; title=&#34;click to delete&#34;
		data-url=&#34;@Url.Action(MVC.UserProfile.EmailDeleteConfirm())&#34; 
		data-template=&#34;UserProfileEmailDeleteUndo&#34;&#62;&#60;/a&#62;
	@Html.Raw(&#34;{{/if}}&#34;)
	&#60;a href=&#34;#&#34; class=&#34;inline-editable-button&#34; title=&#34;click to edit&#34; 
		data-template=&#34;UserProfileEmailEdit&#34; &#62;
		&#60;span class=&#34;ui-icon ui-icon-pencil&#34;&#62;&#60;/span&#62;
		&#60;span class=&#34;user-profile-email-address&#34;&#62;${Address}&#60;/span&#62;
	&#60;/a&#62;
	@Html.Raw(&#34;{{else}}&#34;)
		&#60;span class=&#34;user-profile-email-address&#34;&#62;${Address}&#60;/span&#62;
	@Html.Raw(&#34;{{/if}}&#34;)
	@Html.Raw(&#34;{{if EmailType}}&#34;)
	&#60;span class=&#34;user-profile-item-type&#34;&#62;(${EmailType})&#60;/span&#62;
	@Html.Raw(&#34;{{/if}}&#34;)
	@Html.Raw(&#34;{{if IsViewingUser}}&#34;)
	&#60;span class=&#34;user-profile-item-share-description&#34; title=&#34;${ShareDescription}&#34;&#62;Visible to: ${Groups}&#60;/span&#62;
	@Html.Raw(&#34;{{/if}}&#34;)
	@Html.Raw(&#34;{{if Comments}}&#34;)
	&#60;span class=&#34;user-profile-email-comment notice&#34;&#62;${Comments}&#60;/span&#62;
	@Html.Raw(&#34;{{else}}&#34;)
	&#60;br /&#62;
	@Html.Raw(&#34;{{/if}}&#34;)
&#60;/span&#62;
@Html.Raw(&#34;{{/if}}&#34;)</pre>
<p>This template also handles the case when the item is deleted by rendering that as sub-template as needed.  Structurally this is the same as the &#8216;EmailEditTemplate&#8217; view.  This looks the same as the &#8216;EmailView&#8217; view, except that this is in template syntax (inside the Razor syntax), instead of binding to a .net view model class.  Another difference from &#8216;EmailView&#8217; view is that we don&#8217;t set the href attribute on the anchor tag buttons.  We know if the template is able to render then script is enabled and the subsequent enhancement to change the anchor tag to a button will also work.</p>
<p>As shown in the following screenshot, MVC renders the view code above as valid template syntax.</p>
<p><a href="http://candordeveloper.files.wordpress.com/2012/07/profile-email-template-source.png"><img class="alignnone  wp-image-171" title="Profile-email-template-source" src="http://candordeveloper.files.wordpress.com/2012/07/profile-email-template-source.png?w=834&#038;h=724" alt="" width="834" height="724" /></a></p>
<h3>&#8216;EmailDeleteUndoTemplate&#8217; View</h3>
<p>The undo delete template only applies to AsyncUI, at least in my example.  If you delete an email without script enabled you get prompted if you are sure, and then you can&#8217;t undo delete.  But if you then load the page with script enabled you&#8217;ll see the items that can be restored with the undo template (deleted section of view template).  This template is relatively short and simple.  It has one button to restore the item, and that button works the same as the buttons on the other client side template views.  Just like the others it also defines the post url via the &#8216;data-url&#8217; attribute and the template to switch to on click with the &#8216;data-template&#8217; attribute.</p>
<pre class="brush: xml; title: ; notranslate" title="">&#60;span class=&#34;inline-editable user-profile-email delete-undo&#34;&#62;
	@Html.Raw(&#34;{{if IsViewingUser}}&#34;) 
	&#60;a href=&#34;#&#34; class=&#34;inline-editable-button&#34; title=&#34;click to undo the delete&#34;
		 data-url=&#34;@Url.Action(MVC.UserProfile.EmailDeleteUndo())&#34; 
		 data-template=&#34;UserProfileEmailView&#34;&#62;
		&#60;span class=&#34;ui-icon ui-icon-alert&#34;&#62;&#60;/span&#62;
		&#60;span&#62;Email address 
			&#60;span class=&#34;user-profile-email-address&#34;&#62;${Address}&#60;/span&#62;
			is deleted.  Click to recover.
		&#60;/span&#62;
	&#60;/a&#62;
	&#60;br /&#62;
	@Html.Raw(&#34;{{/if}}&#34;)
&#60;/span&#62;</pre>
<h3>&#8216;EmailDelete&#8217; View</h3>
<p>The delete view is only used when script is disabled.  It prompts the user if they are sure that they want to delete the item.  If so it posts to the EmailDeleteConfirm action.  This is the same action method as the client side view template delete button.  Look back at the EmailDeleteConfirm controller action method to see how it handles both at the same time.</p>
<pre class="brush: xml; title: ; notranslate" title="">@model XQuiSoft.Xulgent.MvcWebApplication.Models.UserProfile.UserProfileEmailViewModel
&#60;span class=&#34;inline-editable user-profile-email&#34;&#62;
@using (Html.BeginForm(MVC.UserProfile.EmailDeleteConfirm()))
{
	&#60;p class=&#34;notice&#34;&#62;
		Are you sure you want to delete this email address from your profile?&#60;/p&#62;
	@Html.HiddenFor(model =&#62; model.ID)
	@Html.HiddenFor(model =&#62; model.UserID)
	&#60;span class=&#34;user-profile-email-address&#34;&#62;@Model.Address&#60;/span&#62;
	@if (!string.IsNullOrEmpty(Model.EmailType)) { 
	&#60;span class=&#34;user-profile-item-type&#34;&#62;(@Model.EmailType)&#60;/span&#62;
	}
	&#60;div class=&#34;&#34;&#62;
		&#60;input type=&#34;submit&#34; value=&#34;Confirm&#34; id=&#34;Confirm&#34; name=&#34;Confirm&#34; class=&#34;link-button ui-state-default ui-corner-all link-button-confirm left-float&#34; /&#62;
		&#60;input type=&#34;submit&#34; value=&#34;Cancel&#34; id=&#34;Cancel&#34; name=&#34;Cancel&#34; class=&#34;link-button ui-state-default ui-corner-all link-button-cancel right-float&#34; /&#62;
		@Html.DisplayFor(model =&#62; model.Results)
		&#60;span class=&#34;msg clear&#34;&#62;&#60;/span&#62;
	&#60;/div&#62;
}
&#60;/span&#62;</pre>
<h3>Custom Command Views</h3>
<p>You can define other views to be handled by this AsycnUI script by just defining the necessary controller action methods and then setting the &#8220;data-url&#8221; and &#8220;data-template&#8221; attributes on the view buttons. It should be able to handle any custom scenario that you can think of.</p>
<h2>The Script</h2>
<p>When one of the &#8216;inline-editable-button&#8217; classed HTML elements is pressed it basically does the following operations in order.</p>
<ol>
<li>Gets the JSON object that represents this item (which was loaded at page load from data-json-var or data-json-url and stored)</li>
<li>Updates the JSON object from the form values (by element name), if applicable.  It supports drilling down to sub-properties and into arrays.</li>
<li>Looks for a template name in the &#8216;data-template&#8217; attribute and replaces the current &#8216;inline-editable&#8217; element with an instance of that template bound to the updated JSON object.  This is why you see the change back to the other view immediately.</li>
<li>If &#8220;data-url&#8221; is not explicitely set to an empty string (as in cancel button) it posts to the url defined by the form and includes the button name as a form variable as well (for the FormPostActionSelector to pick up).  You can override the post url per button with a &#8220;data-url&#8221; attribute on the button (not shown above).  The button can also define a &#8220;url-method&#8221; attribute if it wants to use something other than the &#8216;post&#8217; verb (not shown above).  &#8221;url-method&#8221; is more commonly used for buttons in the non-form (read-only) views.
<ul>
<li>On post success if the item was passed back it replaces the template again with the new model.  This is in place for the times when some properties are calculated on the server from other inputs.  The server side also has the option of returning the name of the template to instantiate if the one defined on the button needs to be overridden due to some special case.</li>
<li>On a post business rule failure the view can toggle back to the edit view and show the error message in your placeholder for errors.  Note the span with class &#8216;msg&#8217; in the template above.</li>
</ul>
</li>
</ol>
<p><del datetime="2012-07-27T01:33:19+00:00">I plan on sharing this script via GitHub soon.  For now you can <a href="http://jsfiddle.net/mjlang/h33DV/8/">find it on jsFiddle</a>.  If you have any ideas for a name on Github, please let me know.</del>  <strong>Update July 26,2012:</strong> This script is now available <a href="https://github.com/michael-lang/jquery-auto-async">on Github, the repo is named jquery-auto-async</a>. I moved parts of the jsFiddle that were a modification of form2js on github into my own fork.  You will need <a href="https://github.com/michael-lang/form2js">my fork of form2js</a> as a dependency.</p>
<p>You will also need <a href="http://jquery.com/">jQuery</a>, <a href="http://jqueryui.com/">jQueryUI</a>, <a href="http://docs.jquery.com/Plugins/Validation/validate">jQuery Validate</a>, and <a href="http://stephenwalther.com/archive/2010/11/30/an-introduction-to-jquery-templates.aspx">jQuery Templates</a>.  If you want to use the &#8216;listbuilder&#8217; widget for one of your inputs you can find that on <a href="https://github.com/michael-lang/jquery-ui">my fork of jQueryUI</a> and find discussion on inclusion of it within jqueryUI on the <a href="http://wiki.jqueryui.com/w/page/12137993/ListBuilder">jQueryUI development wiki</a>.</p>
<p>The templates in this article currently use the now deprecated jQuery Templates library.  You could just as easily use any other templating solution with a couple line modification to the <a href="https://github.com/michael-lang/jquery-auto-async">jquery-auto-async</a> script.  I am still using this template solution for now since the jQuery team is working on a replacement.  It really has little bearing on the functionality of this sample code, so I didn&#8217;t take the time to update it to another template library yet.</p>
<h2>Styles</h2>
<p>In my project I am using the themeroller style of my choice, plus the following structural styles.</p>
<pre class="brush: css; title: ; notranslate" title="">.inline-editable .ui-icon { display:inline-block;}
.inline-editable a {text-decoration:none;}
a.inline-editable-button span {font-weight:bold;color:Black;}
span.delete-undo {background-color:#DDDDDD; border:1px solid #BBBBBB; display:inline-block;width:100%;}</pre>
]]></content:encoded>
</item>
<item>
<title><![CDATA[how to create mobile application in mvc]]></title>
<link>http://randeeprana.wordpress.com/2012/07/17/how-to-create-mobile-application-in-mvc/</link>
<pubDate>Tue, 17 Jul 2012 07:19:02 +0000</pubDate>
<dc:creator>randeeprana</dc:creator>
<guid>http://randeeprana.wordpress.com/2012/07/17/how-to-create-mobile-application-in-mvc/</guid>
<description><![CDATA[http://operationmobile.com/how-to-create-a-jquery-mobile-app-using-asp-net-mvc/]]></description>
<content:encoded><![CDATA[<p><a href="http://operationmobile.com/how-to-create-a-jquery-mobile-app-using-asp-net-mvc/">http://operationmobile.com/how-to-create-a-jquery-mobile-app-using-asp-net-mvc/</a></p>
]]></content:encoded>
</item>
<item>
<title><![CDATA[Bang! Bang! Bang! Bang! Bang! Bang! Bang! Bang! Bang!: Deadpool Is Getting His Crack At Videogame Fame]]></title>
<link>http://thisisbrandonb.wordpress.com/2012/07/15/bang-bang-bang-bang-bang-bang-bang-bang-bang-deadpool-is-getting-his-crack-at-videogame-fame-2/</link>
<pubDate>Sun, 15 Jul 2012 04:17:00 +0000</pubDate>
<dc:creator>thisisbrandonb</dc:creator>
<guid>http://thisisbrandonb.wordpress.com/2012/07/15/bang-bang-bang-bang-bang-bang-bang-bang-bang-deadpool-is-getting-his-crack-at-videogame-fame-2/</guid>
<description><![CDATA[Up until now, Deadpool has been kept in the back burner of Marvel&#8217;s team of super-powered prot]]></description>
<content:encoded><![CDATA[<div class="separator" style="clear:both;text-align:center;"><a href="http://thisisbrandonb.files.wordpress.com/2012/07/deadpoolmvc3.jpg" style="margin-left:1em;margin-right:1em;"><img border="0" height="217" src="http://thisisbrandonb.files.wordpress.com/2012/07/deadpoolmvc3.jpg?w=400&#038;h=217" width="400" /></a></div>
<div class="separator" style="clear:both;text-align:center;"></div>
<div style="text-align:center;">
<div style="text-align:left;"><span style="font-family:Verdana, sans-serif;">Up until now, Deadpool has been kept in the back burner of Marvel&#8217;s team of super-powered protagonists. Between 1991 and about, let&#8217;s say, 2009, only hardcore comic fans would have any inkling of who this humorous homicidal maniac is. Since his appearances as the near-unstoppable, silent bad guy in 2009&#8242;s <i>X-Men Origins: Wolverine</i>, his usual loudmouth, havoc-wreaking self in 2011&#8242;s popular video game <i>Marvel Vs. Capcom 3 (</i>and among other minor video game roles), he&#8217;s been getting some shine and in late 2012/early 2013 our new favorite anti-hero will be getting the recognition he deserves with his own video game. Geeks everywhere are rejoicing. The only issue I have is the &#8220;Suck it Wolverine&#8221; jab he throws at the end of the trailer but we already know why he&#8217;s mad in the first place. View and enjoy:</span></div>
</div>
<div style="text-align:center;"></div>
<p><span class='embed-youtube' style='text-align:center; display: block;'><iframe class='youtube-player' type='text/html' width='640' height='390' src='http://www.youtube.com/embed/vV21ZLbi0hs?version=3&#038;rel=1&#038;fs=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;wmode=transparent' frameborder='0'></iframe></span><br /><span style="text-align:center;"><br /></span><br /><span style="text-align:center;">Source: (</span><a href="http://snubbxsupremacy.tumblr.com/post/27235424409/herochan-first-official-deadpool-the-game" style="text-align:center;">Tumblr</a><span style="text-align:center;">)</span></p>
]]></content:encoded>
</item>

</channel>
</rss>
