<?xml version="1.0" encoding="UTF-8"?><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/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Ricardo Covo</title>
	<atom:link href="https://ricardocovo.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://ricardocovo.wordpress.com</link>
	<description>Sharing software development experiences</description>
	<lastBuildDate>Wed, 12 Nov 2014 02:29:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>

<image>
	<url>https://ricardocovo.wordpress.com/wp-content/uploads/2023/12/favicon-16x16-1.png?w=16</url>
	<title>Ricardo Covo</title>
	<link>https://ricardocovo.wordpress.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<cloud domain='ricardocovo.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<atom:link rel="search" type="application/opensearchdescription+xml" href="https://ricardocovo.wordpress.com/osd.xml" title="Ricardo Covo" />
	<atom:link rel='hub' href='https://ricardocovo.wordpress.com/?pushpress=hub'/>
	<item>
		<title>Form swapping with ASP.Net MVC 4, jQuery and Ajax</title>
		<link>https://ricardocovo.wordpress.com/2013/01/24/form-swapping-using-asp-net-mvc4-jquery-and-ajax/</link>
					<comments>https://ricardocovo.wordpress.com/2013/01/24/form-swapping-using-asp-net-mvc4-jquery-and-ajax/#comments</comments>
		
		<dc:creator><![CDATA[ricardocovo]]></dc:creator>
		<pubDate>Thu, 24 Jan 2013 22:36:29 +0000</pubDate>
				<category><![CDATA[.Net Development]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[ASP.Net Development]]></category>
		<category><![CDATA[ASP.Net MVC]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[dynamic]]></category>
		<category><![CDATA[form]]></category>
		<category><![CDATA[form swap]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[source code]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[user experience]]></category>
		<category><![CDATA[ux]]></category>
		<guid isPermaLink="false">http://ricardocovo.com/?p=251</guid>

					<description><![CDATA[In this screen cast I will demonstrate how swap forms within in a section of your page using jQuery and AJAX. This technique allows you to make your web sites faster and provide an easier (and better user experience). Get the source code by clicking here.]]></description>
										<content:encoded><![CDATA[<p>In this screen cast I will demonstrate how swap forms within in a section of your page using jQuery and AJAX.</p>
<p>This technique allows you to make your web sites faster and provide an easier (and better user experience).</p>
<div class="jetpack-video-wrapper"><iframe class="youtube-player" width="840" height="473" src="https://www.youtube.com/embed/sB7nZUsceGI?version=3&#038;rel=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;fs=1&#038;hl=en&#038;autohide=2&#038;wmode=transparent" allowfullscreen="true" style="border:0;" sandbox="allow-scripts allow-same-origin allow-popups allow-presentation allow-popups-to-escape-sandbox"></iframe></div>
<p><a href="http://webnodes.ca/media/FormSwapDemo.zip" target="_blank">Get the source code by clicking here</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ricardocovo.wordpress.com/2013/01/24/form-swapping-using-asp-net-mvc4-jquery-and-ajax/feed/</wfw:commentRss>
			<slash:comments>9</slash:comments>
		
		
		
		<media:content url="https://0.gravatar.com/avatar/96d702c5c05363da66078eb901f3f49282ade8d99a52ea28952e666ba560c314?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ricardocovo</media:title>
		</media:content>
	</item>
		<item>
		<title>Financial Functions in .Net (C#)</title>
		<link>https://ricardocovo.wordpress.com/2013/01/14/financial-functions-in-net-c/</link>
					<comments>https://ricardocovo.wordpress.com/2013/01/14/financial-functions-in-net-c/#comments</comments>
		
		<dc:creator><![CDATA[ricardocovo]]></dc:creator>
		<pubDate>Mon, 14 Jan 2013 17:34:51 +0000</pubDate>
				<category><![CDATA[.Net Development]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[financial]]></category>
		<category><![CDATA[library]]></category>
		<guid isPermaLink="false">http://ricardocovo.wordpress.com/?p=247</guid>

					<description><![CDATA[I recently worked on a project where I had to perform financial calculations. The main project requirements where provided on an Excel and because of the sensitivity of the calculations(mortgage payments), I had to keep within 1cent accuracy. After reviewing the needed calculations, my main issue was the NPV (Net Present Value); although I am &#8230; <a href="https://ricardocovo.wordpress.com/2013/01/14/financial-functions-in-net-c/" class="more-link">Continue reading<span class="screen-reader-text"> "Financial Functions in .Net&#160;(C#)"</span></a>]]></description>
										<content:encoded><![CDATA[<p>I recently worked on a project where I had to perform financial calculations. The main project requirements where provided on an Excel and because of the sensitivity of the calculations(mortgage payments), I had to keep within 1cent accuracy.</p>
<p>After reviewing the needed calculations, my main issue was the NPV (Net Present Value); although I am familiar with the formula and applications of NPV, I was not sure of the exact implementation in Excel.</p>
<p>So, I jumped to Google to see if there was any implementations and found the <a href="http://archive.msdn.microsoft.com/FinancialFunctions" target="_blank">Excel Financial Functions for .Net</a>: “… a .NET library that provides the full set of financial functions from Excel.”.</p>
<p>Great! <strong>BUT. </strong>The library is actually implemented in F# and only the source code is provided, no compiled version…. No problem, since all .Net languages compile into IL (Intermediate Language), all I needed to do was to compile the F# project and then reference it on my C# one.</p>
<p>After I add ed the Financial.dll reference to my project (compiled version included in the provided <a href="http://www.webnodes.ca/media/4193/FinancialFunctionsSample.zip" target="_blank">source code</a>), I am ready to use it on my code, however, note that the following reference is required:</p>
<p><span style="color:#0000ff;">using </span></p>
<pre>System.Numeric;</pre>
<p>&nbsp;</p>
<p>With the reference in place, I can now use the NPV function as follow:</p>
<p><a href="https://ricardocovo.wordpress.com/wp-content/uploads/2013/01/financials.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border:0;" title="Financials" src="https://ricardocovo.wordpress.com/wp-content/uploads/2013/01/financials_thumb.png?w=504&#038;h=83" alt="Financials" width="504" height="83" border="0" /></a></p>
<p>Comparing the signature of the NPV function on Financial.dll to excel, we can see they are virtually the same:</p>
<p><a href="https://ricardocovo.wordpress.com/wp-content/uploads/2013/01/financials-excel.png"><img style="background-image:none;padding-top:0;padding-left:0;display:inline;padding-right:0;border:0;" title="Financials-Excel" src="https://ricardocovo.wordpress.com/wp-content/uploads/2013/01/financials-excel_thumb.png?w=228&#038;h=82" alt="Financials-Excel" width="228" height="82" border="0" /></a></p>
<p>And even though I have shown mainly the NPV usage, this library contains implementation pretty much all financial functions in Excel (<a href="http://office.microsoft.com/client/helppreview.aspx?AssetID=HP100791841033&amp;ns=EXCEL&amp;lcid=1033" target="_blank">Complete List</a>).</p>
<p>There you have it; if you ever have a project where you need to use Excel functions, you can refer t the Excel Financial Functions for .Net library; you can use the compiled library provided on this example, but I recommend reviewing the library page regularly to check for updates.</p>
<p>Hope this helps!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ricardocovo.wordpress.com/2013/01/14/financial-functions-in-net-c/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		
		<media:content url="https://0.gravatar.com/avatar/96d702c5c05363da66078eb901f3f49282ade8d99a52ea28952e666ba560c314?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ricardocovo</media:title>
		</media:content>

		<media:content url="https://ricardocovo.wordpress.com/wp-content/uploads/2013/01/financials_thumb.png" medium="image">
			<media:title type="html">Financials</media:title>
		</media:content>

		<media:content url="https://ricardocovo.wordpress.com/wp-content/uploads/2013/01/financials-excel_thumb.png" medium="image">
			<media:title type="html">Financials-Excel</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP MVC3 – Editing records with jQueryUI Dialogs and AjaxForms &#8211; Razor Version</title>
		<link>https://ricardocovo.wordpress.com/2012/04/06/asp-mvc3-editing-records-with-jqueryui-dialogs-and-ajaxforms-razor-version/</link>
					<comments>https://ricardocovo.wordpress.com/2012/04/06/asp-mvc3-editing-records-with-jqueryui-dialogs-and-ajaxforms-razor-version/#comments</comments>
		
		<dc:creator><![CDATA[ricardocovo]]></dc:creator>
		<pubDate>Fri, 06 Apr 2012 18:22:31 +0000</pubDate>
				<category><![CDATA[.Net Development]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[ASP.Net Development]]></category>
		<category><![CDATA[ASP.Net MVC]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[dialogs]]></category>
		<category><![CDATA[jqueryui]]></category>
		<category><![CDATA[MVC]]></category>
		<guid isPermaLink="false">http://ricardocovo.com/?p=207</guid>

					<description><![CDATA[This post is in response to the several requests I&#8217;ve gotten to provide a Razor version of a sample solution I provided a few months ago on Editing records with jQueryUI Dialogs and AjaxForms, which was originally posted using aspx views. If you haven&#8217;t read it or seen the video, please take a look at it &#8230; <a href="https://ricardocovo.wordpress.com/2012/04/06/asp-mvc3-editing-records-with-jqueryui-dialogs-and-ajaxforms-razor-version/" class="more-link">Continue reading<span class="screen-reader-text"> "ASP MVC3 – Editing records with jQueryUI Dialogs and AjaxForms &#8211; Razor&#160;Version"</span></a>]]></description>
										<content:encoded><![CDATA[<p>This post is in response to the several requests I&#8217;ve gotten to provide a Razor version of a sample solution I provided a few months ago on <a title="ASP MVC3 – Editing records with jQueryUI Dialogs and AjaxForms" href="http://ricardocovo.com/2011/04/03/asp-mvc3-editing-records-with-jqueryui-dialogs-and-ajaxforms/" target="_blank">Editing records with jQueryUI Dialogs and AjaxForms</a>, which was originally posted using aspx views. If you haven&#8217;t read it or <a href="http://www.youtube.com/watch?v=3BJssRnHa7A" target="_blank">seen the video,</a> please take a look at it first; as most of the concepts will remain the same. .</p>
<p>So this solution is practically unchanged compared to the original, however I did I introduced 2 improvements (which could also apply to the aspx version).</p>
<ol>
<li>I realized after I did my original post that I was able to get <strong>data</strong> on the handler function from the ajax form; so I am no longer looking into the response div for my data (which was kind of a hack). Instead I am now using it properly by receiving the data directly.</li>
<li>I use a JsonStandardResponse, which I have been using in my projects succesfully and make things a bit easier. (See my previous post: <a title="ASP.Net MVC: Using Json Standard Responses for your Ajax Calls" href="http://ricardocovo.com/2012/03/08/asp-net-mvc-using-json-standard-responses-for-your-ajax-calls/" target="_blank">Json Standard Responses for your Ajax Calls</a>). So the controller action was changed to return JsonResult instead of a regular ActionResult with Content.</li>
</ol>
<div>Here are the details of the change in the controller:</div>
<pre class="brush: csharp; title: ; notranslate">
[HttpPost]
public JsonResult Edit(CarModel model) {
if (ModelState.IsValid)
{
CarModel car = CarRepository.GetCars().Where(c =&gt; c.Id == model.Id).FirstOrDefault();
car.Name = model.Name;
car.Description = model.Description;
return Json(JsonResponseFactory.SuccessResponse(car),JsonRequestBehavior.DenyGet);
}
else {
return Json(JsonResponseFactory.ErrorResponse(&quot;Please review your form&quot;), 
            JsonRequestBehavior.DenyGet);
}
}
</pre>
<p><span id="more-207"></span></p>
<pre></pre>
<p>Notice that if the <strong>ModelState</strong> is valid I proceed with the change , and regurn a <strong>SuccessResponse</strong>, which includes the object <strong>car</strong> (this will get added to the standard json response).</p>
<pre class="brush: csharp; title: ; notranslate">
return Json(JsonResponseFactory.SuccessResponse(car),JsonRequestBehavior.DenyGet);
</pre>
<p>If the state is not valid, we will return a <strong>ErrorResponse</strong>:</p>
<pre class="brush: csharp; title: ; notranslate">
return Json(JsonResponseFactory.ErrorResponse(&quot;Please review your form&quot;),
            JsonRequestBehavior.DenyGet);
</pre>
<p>With the Controller ready,  the UpdateSucces function (which is specified as the OnSuccess handler for the Ajax Form) is now as follow:</p>
<pre class="brush: jscript; title: ; notranslate">
function updateSuccess(data) {
 if (data.Success == true) {
 //we update the table's info
 var parent = linkObj.closest(&quot;tr&quot;);
 parent.find(&quot;.carName&quot;).html(data.Object.Name);
 parent.find(&quot;.carDescription&quot;).html(data.Object.Description);
 //now we can close the dialog
 $('#updateDialog').dialog('close');
 //twitter type notification
 $('#commonMessage').html(&quot;Update Complete&quot;);
 $('#commonMessage').delay(400).slideDown(400).delay(3000).slideUp(400);
 }
 else {
 $(&quot;#update-message&quot;).html(data.ErrorMessage);
 $(&quot;#update-message&quot;).show();
 }
}
</pre>
<p>This, compared to the original implementation is much cleaner, because we get the data in json form directly in the function, and thanks to the JsonStandardResponse, I also get a copy of the updated object.</p>
<p>That is it. Those are the only two updates.</p>
<p><a href="http://www.webnodes.ca/media/4199/EditDialogsAndFormsRazor-Demo.zip" target="_blank">Download the Source Code.</a></p>
<p>Hope this helps!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ricardocovo.wordpress.com/2012/04/06/asp-mvc3-editing-records-with-jqueryui-dialogs-and-ajaxforms-razor-version/feed/</wfw:commentRss>
			<slash:comments>67</slash:comments>
		
		
		
		<media:content url="https://0.gravatar.com/avatar/96d702c5c05363da66078eb901f3f49282ade8d99a52ea28952e666ba560c314?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ricardocovo</media:title>
		</media:content>
	</item>
		<item>
		<title>Three ways to get started with KendoUI Grids on ASP.NET MVC</title>
		<link>https://ricardocovo.wordpress.com/2012/03/26/three-ways-to-get-started-with-kendoui-grids-on-asp-net-mvc/</link>
					<comments>https://ricardocovo.wordpress.com/2012/03/26/three-ways-to-get-started-with-kendoui-grids-on-asp-net-mvc/#comments</comments>
		
		<dc:creator><![CDATA[ricardocovo]]></dc:creator>
		<pubDate>Mon, 26 Mar 2012 19:02:24 +0000</pubDate>
				<category><![CDATA[.Net Development]]></category>
		<category><![CDATA[ASP.Net MVC]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[kendoui]]></category>
		<category><![CDATA[MVC]]></category>
		<guid isPermaLink="false">http://ricardocovo.com/?p=187</guid>

					<description><![CDATA[&#8212; Disclaimer: I do not work for KendoUI (Telerik) and I am not getting anything in return for this entry&#8230; I just like the library 😉 Over the past months I have been evaluating the KendoUI library and using it on my pet projects. I really like it, is evolving very fast and has good &#8230; <a href="https://ricardocovo.wordpress.com/2012/03/26/three-ways-to-get-started-with-kendoui-grids-on-asp-net-mvc/" class="more-link">Continue reading<span class="screen-reader-text"> "Three ways to get started with KendoUI Grids on ASP.NET&#160;MVC"</span></a>]]></description>
										<content:encoded><![CDATA[<p><em>&#8212; Disclaimer: I<strong> do not</strong> work for KendoUI (Telerik) and I am not getting anything in return for this entry&#8230; I just like the library <img src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></em></p>
<p>Over the past months I have been evaluating the KendoUI library and using it on my pet projects. I really like it, is evolving very fast and has good community around it.</p>
<p>KendoUI Grids are very flexible and can be used in many different ways. In this post I will show how you can get started with KendoUI grids on your ASP.NET MVC Projects., I will show you three different ways I have used them, which include Creating the Grid starting from a basic ASP.NET MVC List Template, Creating the grid over an empty div with a remote data source, and finally, how to create a grid using KendoUI templates.</p>
<p>These walk-troughs will cover most of the basics but are only intended to get you started; I encourage you to go to <a href="http://kendoui.com" target="_blank">KendoUI.com</a> and view all other options/configurations/methods available.</p>
<p><a href="http://www.webnodes.ca/media/4205/DataGridKendoUIDemo.zip" target="_blank">Download the Code</a></p>
<p><strong>Method 1: Grid over Existing HTML</strong></p>
<p>In this example, we start from the MVC List Template and convert it to a fully functional grid with pagination and sorting.</p>
<div class="jetpack-video-wrapper"><iframe class="youtube-player" width="840" height="473" src="https://www.youtube.com/embed/IZvj00n26wE?version=3&#038;rel=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;fs=1&#038;hl=en&#038;autohide=2&#038;wmode=transparent" allowfullscreen="true" style="border:0;" sandbox="allow-scripts allow-same-origin allow-popups allow-presentation allow-popups-to-escape-sandbox"></iframe></div>
<p><strong><span id="more-187"></span>Method 2: Grid over an Empty Div</strong></p>
<p>In this example, we start over an empty div and use a remote data source. We modify our controller to provide the required Json. The result is a grid that allows paging, sorting, grouping and filtering.</p>
<div class="jetpack-video-wrapper"><iframe class="youtube-player" width="840" height="473" src="https://www.youtube.com/embed/PkeBZkqVcrs?version=3&#038;rel=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;fs=1&#038;hl=en&#038;autohide=2&#038;wmode=transparent" allowfullscreen="true" style="border:0;" sandbox="allow-scripts allow-same-origin allow-popups allow-presentation allow-popups-to-escape-sandbox"></iframe></div>
<p><strong>Method 3: Grid Using Templates</strong></p>
<p>We start from the MVC Template List, and convert it to a Grid that uses remote data source and is fully functional. This is my prefer method because it provides  simplicity when modifying the grid presentation, and has the power of the remote datasource.</p>
<div class="jetpack-video-wrapper"><iframe class="youtube-player" width="840" height="473" src="https://www.youtube.com/embed/cxCafVGN63I?version=3&#038;rel=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;fs=1&#038;hl=en&#038;autohide=2&#038;wmode=transparent" allowfullscreen="true" style="border:0;" sandbox="allow-scripts allow-same-origin allow-popups allow-presentation allow-popups-to-escape-sandbox"></iframe></div>
]]></content:encoded>
					
					<wfw:commentRss>https://ricardocovo.wordpress.com/2012/03/26/three-ways-to-get-started-with-kendoui-grids-on-asp-net-mvc/feed/</wfw:commentRss>
			<slash:comments>11</slash:comments>
		
		
		
		<media:content url="https://0.gravatar.com/avatar/96d702c5c05363da66078eb901f3f49282ade8d99a52ea28952e666ba560c314?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ricardocovo</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.Net MVC: Using Json Standard Responses for your Ajax Calls</title>
		<link>https://ricardocovo.wordpress.com/2012/03/08/asp-net-mvc-using-json-standard-responses-for-your-ajax-calls/</link>
					<comments>https://ricardocovo.wordpress.com/2012/03/08/asp-net-mvc-using-json-standard-responses-for-your-ajax-calls/#comments</comments>
		
		<dc:creator><![CDATA[ricardocovo]]></dc:creator>
		<pubDate>Thu, 08 Mar 2012 21:49:16 +0000</pubDate>
				<category><![CDATA[.Net Development]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[ASP.Net MVC]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[MVC]]></category>
		<guid isPermaLink="false">http://ricardocovo.com/?p=165</guid>

					<description><![CDATA[For the past couple of years, after we started our move towards ASP.Net MVC, we have been using more and more ajax to enrich our user interface and we love it. At the begining we use to send our responses as simple strings (true/false) or very customized Json responses. However, for the past year or &#8230; <a href="https://ricardocovo.wordpress.com/2012/03/08/asp-net-mvc-using-json-standard-responses-for-your-ajax-calls/" class="more-link">Continue reading<span class="screen-reader-text"> "ASP.Net MVC: Using Json Standard Responses for your Ajax&#160;Calls"</span></a>]]></description>
										<content:encoded><![CDATA[<p>For the past couple of years, after we started our move towards ASP.Net MVC, we have been using more and more ajax to enrich our user interface and we love it.</p>
<p>At the begining we use to send our responses as simple strings (true/false) or very customized Json responses. However, for the past year or so we&#8217;ve been using Standard Json Responses and it has been working great. I&#8217;ve passed this idea to a couple of friends and everyone seems to like it so here it is.</p>
<p><strong>Objective &amp; Advantages</strong></p>
<p>The objective will be to have standard Json Responses to our AJAX calls that we can easily re-use accross our application, independent of what action or what objects we are working with&#8230; And by having and standard responses, we can have a standard way to handle them.</p>
<p><a href="http://www.webnodes.ca/media/4187/JsonStandardResponseDemo.zip" target="_blank">Download the Code</a><br />
<span id="more-165"></span><br />
<strong>The JSON Response Factory</strong></p>
<p>This is what we have been using to generate the Standard Response  (yes, is VERY simple) . By having the factory and reusing it across the application we are basically enforcing the standard:</p>
<pre class="brush: csharp; title: ; notranslate">
public class JsonResponseFactory
{
 public static object ErrorResponse(string error) {
 return new { Success = false, ErrorMessage = error };
 }

public static object SuccessResponse() {
 return new { Success = true};
 }

public static object SuccessResponse(object referenceObject)
 {
 return new { Success = true, Object = referenceObject };
 }

}</pre>
<p>The main thing to notice is that we are using dynamic objects; we do so (instead of a plain class) so we can easily return only what it is necessary.</p>
<p>Now let&#8217;s dig in. It is very simple, but lets pick it apart function by function:</p>
<pre class="brush: csharp; title: ; notranslate">

public static object ErrorResponse(string error) {
return new { Success = false, ErrorMessage = error };
}
</pre>
<p>This function generates an object that has a Success flag, which is set to false (is an error), and an ErrorMessage. We force the error responses to have an error message, although you can chose to do it differently.</p>
<pre class="brush: csharp; title: ; notranslate">
public static object SuccessResponse() {
 return new { Success = true};
 }
</pre>
<p>This is probably the simplest one, but one of the one we use the most. The function generates an object with Success equals to true and that is it. It is used a lot for functions such as &#8220;Delete&#8221;.</p>
<pre class="brush: csharp; title: ; notranslate">
public static object SuccessResponse(object referenceObject)
 {
 return new { Success = true, Object = referenceObject };
 }
</pre>
<p>Finally there is the function that generates a response with a reference object inside. This function is useful when you need to send an object (Get type of funcitons).</p>
<p><strong>The Controller: Let&#8217;s use those cool responses!</strong></p>
<p>So now we know how to build our responses. Here is how you would send it back on your controller &#8211; you all probably already know <img src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<pre class="brush: csharp; title: ; notranslate">
[HttpPost]
public JsonResult DeleteSuccess(int? id) {
 return Json(JsonResponseFactory.SuccessResponse());
}

[HttpPost]
public JsonResult DeleteError(int? id)
{
 return Json(JsonResponseFactory.ErrorResponse(&quot;Some Error... Can't delete!&quot;));
}

[HttpPost]
public JsonResult GetCarSuccess(int? id)
{
 //NOTE: For this example I am using a dynamic object, but the idea is that it could be any object
 var car = new { Name = &quot;Toyota Yaris&quot;, Price = &quot;10000&quot;, Color = &quot;Red&quot; };
 return Json(JsonResponseFactory.SuccessResponse(car));
}
</pre>
<p>Now, notice that our functions are returning a JsonResults (I also specified the Verb (HttpPost), you can omit it if you want), but the magic happens here:</p>
<pre class="brush: csharp; title: ; notranslate">return Json(JsonResponseFactory.SuccessResponse(car));</pre>
<p>Because &#8220;Json&#8221; takes any object and converts it into JSon, is basically allowing us to send anything we want back. In this example, we are returning a standard response,with a reference object (&#8216;car&#8217;) in it and it will be converted into Json for us&#8230; that was easy <img src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p><strong>On the Client Side! Handle the Response</strong></p>
<p>The server side is ready, now let&#8217;s see a sample of how to handle the response on the client side.</p>
<pre class="brush: jscript; title: ; notranslate">

$(function () {
   $(&quot;.test-link&quot;).click(function (e) {
     e.preventDefault;
     $.post(&quot;controller/action&quot;, function (data) {
        if (data.Success == true) {
           alert(&quot;Success&quot;);
           if (data.Object != null){
              //here I could call the properties of my object, as below:
              alert(data.Object.Name); //assuming your object has a property name
            }
         }
         else {alert(data.ErrorMessage);}
       });
       return false;
    });
});
</pre>
<p>This code simulates a click event that posts into our controller using jQuery. Because the response (data) is automatically converted into an jQuery object, you can use it immediately. Notice that I am calling the property names that I assign on the factory such as &#8220;Success&#8221;, &#8220;ErrorMessage&#8221; and &#8220;Object&#8221;.<br />
Inside the data.Object there will be any object that you specified on your server side code, and you can use it accordingly. In the snippet above, we are assuming the object will have a property called &#8220;Name&#8221;.<br />
That is pretty much it! Simple, but it has saved us a lot of time. You can create your own standards, but the important thing is that it is maintained across your application and that the development team is made aware of it so they can quickly use it on their tasks.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ricardocovo.wordpress.com/2012/03/08/asp-net-mvc-using-json-standard-responses-for-your-ajax-calls/feed/</wfw:commentRss>
			<slash:comments>17</slash:comments>
		
		
		
		<media:content url="https://0.gravatar.com/avatar/96d702c5c05363da66078eb901f3f49282ade8d99a52ea28952e666ba560c314?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ricardocovo</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP MVC3 &#8211; Editing records with jQueryUI Dialogs and AjaxForms</title>
		<link>https://ricardocovo.wordpress.com/2011/04/03/asp-mvc3-editing-records-with-jqueryui-dialogs-and-ajaxforms/</link>
					<comments>https://ricardocovo.wordpress.com/2011/04/03/asp-mvc3-editing-records-with-jqueryui-dialogs-and-ajaxforms/#comments</comments>
		
		<dc:creator><![CDATA[ricardocovo]]></dc:creator>
		<pubDate>Sun, 03 Apr 2011 14:58:53 +0000</pubDate>
				<category><![CDATA[.Net Development]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[ASP.Net Development]]></category>
		<category><![CDATA[ASP.Net MVC]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<guid isPermaLink="false">http://ricardocovo.wordpress.com/?p=123</guid>

					<description><![CDATA[In this screen cast I will show you a demo of how to use  jQueryUI dialogs and MVC AjaxForms to create a rich and simple experience for users when editing records. The technique is simple; you dynamically load a partial view into the DIV dialog  . There are a few tricks to wire up the validation, &#8230; <a href="https://ricardocovo.wordpress.com/2011/04/03/asp-mvc3-editing-records-with-jqueryui-dialogs-and-ajaxforms/" class="more-link">Continue reading<span class="screen-reader-text"> "ASP MVC3 &#8211; Editing records with jQueryUI Dialogs and&#160;AjaxForms"</span></a>]]></description>
										<content:encoded><![CDATA[<p style="text-align:left;">In this screen cast I will show you a demo of how to use  jQueryUI dialogs and MVC AjaxForms to create a rich and simple experience for users when editing records.</p>
<p style="text-align:left;">The technique is simple; you dynamically load a partial view into the DIV dialog  . There are a few tricks to wire up the validation, and to identify success over failure. .</p>
<p style="text-align:left;"><div class="jetpack-video-wrapper"><iframe class="youtube-player" width="840" height="473" src="https://www.youtube.com/embed/3BJssRnHa7A?version=3&#038;rel=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;fs=1&#038;hl=en&#038;autohide=2&#038;wmode=transparent" allowfullscreen="true" style="border:0;" sandbox="allow-scripts allow-same-origin allow-popups allow-presentation allow-popups-to-escape-sandbox"></iframe></div></p>
<p style="text-align:left;"><a href="http://www.webnodes.ca/media/4190/Demo-DeleteConfirmationDialog.zip">Get the source code by clicking here</a>, take a look and let me know what you think.</p>
<p style="text-align:left;font-size:larger;"><em><strong>Update: </strong></em></p>
<p style="text-align:left;"><em>After many requests, I&#8217;ve created a Razor version, all interested can<a title="ASP MVC3 – Editing records with jQueryUI Dialogs and AjaxForms – Razor Version" href="http://ricardocovo.com/2012/04/06/asp-mvc3-editing-records-with-jqueryui-dialogs-and-ajaxforms-razor-version/" target="_blank"><strong> read the post here. </strong></a></em></p>
]]></content:encoded>
					
					<wfw:commentRss>https://ricardocovo.wordpress.com/2011/04/03/asp-mvc3-editing-records-with-jqueryui-dialogs-and-ajaxforms/feed/</wfw:commentRss>
			<slash:comments>76</slash:comments>
		
		
		
		<media:content url="https://0.gravatar.com/avatar/96d702c5c05363da66078eb901f3f49282ade8d99a52ea28952e666ba560c314?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ricardocovo</media:title>
		</media:content>
	</item>
		<item>
		<title>Quick Fix for AddThis.com&#8217;s Facebook Like Button in IIS7.0</title>
		<link>https://ricardocovo.wordpress.com/2011/03/25/quick-fix-for-addthis-on-is7/</link>
					<comments>https://ricardocovo.wordpress.com/2011/03/25/quick-fix-for-addthis-on-is7/#comments</comments>
		
		<dc:creator><![CDATA[ricardocovo]]></dc:creator>
		<pubDate>Fri, 25 Mar 2011 20:58:29 +0000</pubDate>
				<category><![CDATA[.Net Development]]></category>
		<category><![CDATA[IIS7]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[addthis.com]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[asp.net mvc]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[iis7]]></category>
		<category><![CDATA[issue]]></category>
		<guid isPermaLink="false">http://ricardocovo.wordpress.com/?p=79</guid>

					<description><![CDATA[In this post I will be addressing how to fix an error with AddThis.com&#8217;s Facebook Like button, that results int he following error: Parser Error Message: The string &#8216;fb:like:layout&#8217; contains too many device filters. There can be only one. But first a bit of background: Addthis.com is one of the most popular widgets out there &#8230; <a href="https://ricardocovo.wordpress.com/2011/03/25/quick-fix-for-addthis-on-is7/" class="more-link">Continue reading<span class="screen-reader-text"> "Quick Fix for AddThis.com&#8217;s Facebook Like Button in&#160;IIS7.0"</span></a>]]></description>
										<content:encoded><![CDATA[<p>In this post I will be addressing how to fix an error with AddThis.com&#8217;s Facebook Like button, that results int he following error:</p>
<blockquote><p><strong>Parser Error Message: </strong>The string &#8216;fb:like:layout&#8217; contains too many device filters. There can be only one.</p></blockquote>
<p><span id="more-79"></span>But first a bit of background: Addthis.com is one of the most popular widgets out there for social sharing. With a few simple clicks you can provide your users with the ability to easily share your content pretty much everywhere.</p>
<p>One of the features they offer is the ability to add the &#8220;Facebook Like&#8221; button, and for that, their code generator will give a snippet containing  something like this:</p>
<pre class="brush: plain; title: ; notranslate">&lt;a class=&quot;addthis_button_facebook_like&quot; fb:like:layout=&quot;button_count&quot;&gt; &lt;/a&gt;</pre>
<p>What they are doing is passing extra information to their widget on how to display the facebook like button. However, IIS 7.0 seems to get confused by the colons in the attribute name (&#8216;<strong>fb:like:layouts</strong>) and thows a parser error. Interestingly enough, this only happens when they are two colons in the attribute name; one colon will work (try it).</p>
<p>I did not have time to investigate the root cause of this; however I needed a quick fix, and it basically came to this: Add the property with Javascript!</p>
<p>1. Remove problematic the attribute from the tag, and add an id so you can recognize it later. The tag will then be as follow:</p>
<pre class="brush: plain; title: ; notranslate">&lt;a class=&quot;addthis_button_facebook_like&quot; id=&quot;facebookLike&quot;&gt; &lt;/a&gt;</pre>
<p>2.  Now add some javascript to manually add the property, I am using  jQuery, and it looks like this::</p>
<pre class="brush: plain; title: ; notranslate">$(function () { $(&quot;facebookLike&quot;).attr(&quot;fb:like:layout&quot;,&quot;button_count&quot;);});</pre>
<p>That is it! A simple and fast work around <img src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>For reference:</p>
<ul>
<li><a title="http://addthis.com" href="http://addthis.com" target="_blank">AddThis.com </a></li>
<li><a title="Facebook Social Widgets" href="http://developers.facebook.com/docs/plugins/" target="_blank">Facebook Social Widgets </a></li>
</ul>
]]></content:encoded>
					
					<wfw:commentRss>https://ricardocovo.wordpress.com/2011/03/25/quick-fix-for-addthis-on-is7/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
		
		<media:content url="https://0.gravatar.com/avatar/96d702c5c05363da66078eb901f3f49282ade8d99a52ea28952e666ba560c314?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ricardocovo</media:title>
		</media:content>
	</item>
		<item>
		<title>In case you missed it: App_Offline.htm</title>
		<link>https://ricardocovo.wordpress.com/2011/01/21/in-case-you-missed-it-app_offline-htm/</link>
					<comments>https://ricardocovo.wordpress.com/2011/01/21/in-case-you-missed-it-app_offline-htm/#respond</comments>
		
		<dc:creator><![CDATA[ricardocovo]]></dc:creator>
		<pubDate>Fri, 21 Jan 2011 04:12:26 +0000</pubDate>
				<category><![CDATA[.Net Development]]></category>
		<category><![CDATA[ASP.Net Development]]></category>
		<category><![CDATA[ASP.Net MVC]]></category>
		<guid isPermaLink="false">http://ricardocovo.wordpress.com/?p=62</guid>

					<description><![CDATA[I recently found out about a featured introduced in ASP.Net 2.0 that makes it pretty easy to take your application offline, which is pretty useful for when you are doing upgrades, releases, etc. I&#8217;m not sure how I missed this as it has been out there for at least a couple of years, but still wanted &#8230; <a href="https://ricardocovo.wordpress.com/2011/01/21/in-case-you-missed-it-app_offline-htm/" class="more-link">Continue reading<span class="screen-reader-text"> "In case you missed it:&#160;App_Offline.htm"</span></a>]]></description>
										<content:encoded><![CDATA[<p>I recently found out about a featured introduced in ASP.Net 2.0 that makes it pretty easy to take your application offline, which is pretty useful for when you are doing upgrades, releases, etc. I&#8217;m not sure how I missed this as it has been out there for at least a couple of years, but still wanted to do a post about it in case other people missed it as well.</p>
<p><span id="more-62"></span>Basically all you have to do is place an HTML file on your root folder with the following name: &#8220;App_Offline.htm&#8221;. Once the file is found, ASP.NET will shut-down the application and stop processing any incoming requests.  Once your down time is over, remove the file (or rename it to something like _App_Offline.htm) and your application will come back to life <img src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>Make sure your file should be at least 512 bytes otherwise you will get some IE errors (404 Errors) . The application still won&#8217;t process any requests, but the user will see an error. If your page is small and you don&#8217;t want to include more information than necessary, the trick is to include some commented code to your file to trick IE into thinking the file is bigger than it is.</p>
<p>Well, that is it. Better late than never <img src="https://s0.wp.com/wp-content/mu-plugins/wpcom-smileys/twemoji/2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /> I hope it helps people who might have missed this like my self.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ricardocovo.wordpress.com/2011/01/21/in-case-you-missed-it-app_offline-htm/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		
		<media:content url="https://0.gravatar.com/avatar/96d702c5c05363da66078eb901f3f49282ade8d99a52ea28952e666ba560c314?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ricardocovo</media:title>
		</media:content>
	</item>
		<item>
		<title>Improving Silicon Halton’s Business Directory</title>
		<link>https://ricardocovo.wordpress.com/2010/09/30/improving-silicon-halton%e2%80%99s-business-directory/</link>
					<comments>https://ricardocovo.wordpress.com/2010/09/30/improving-silicon-halton%e2%80%99s-business-directory/#respond</comments>
		
		<dc:creator><![CDATA[ricardocovo]]></dc:creator>
		<pubDate>Fri, 01 Oct 2010 02:42:12 +0000</pubDate>
				<category><![CDATA[Business Groups]]></category>
		<category><![CDATA[Business]]></category>
		<category><![CDATA[Networking]]></category>
		<category><![CDATA[Silicon Halton]]></category>
		<guid isPermaLink="false">http://ricardocovo.wordpress.com/?p=54</guid>

					<description><![CDATA[About Silicon Halton In a nut shell, Silicon Halton is a group dedicated to connecting and creating strong and local relationships for hi tech entrepreneurs and leaders in the Halton region. I have been attending Silicon Halton&#8217;s meetings (and un-meetings) for a few months now (http://www.siliconhalton.com/); I am both impressed and encouraged by the groups &#8230; <a href="https://ricardocovo.wordpress.com/2010/09/30/improving-silicon-halton%e2%80%99s-business-directory/" class="more-link">Continue reading<span class="screen-reader-text"> "Improving Silicon Halton’s Business&#160;Directory"</span></a>]]></description>
										<content:encoded><![CDATA[<h2>About Silicon Halton</h2>
<p>In a nut shell, Silicon Halton is a group dedicated to connecting and creating strong and local relationships for hi tech entrepreneurs and leaders in the Halton region.</p>
<p>I have been attending Silicon Halton&#8217;s meetings (and un-meetings) for a few months now (<a href="http://www.siliconhalton.com/">http://www.siliconhalton.com/</a>); I am both impressed and encouraged by the groups potential; obviously there is networking and the possibility of making new business connections, but the group also aims to play a role in the Halton business community as a whole… and that is what&#8217;s kept me going back!</p>
<h2><span id="more-54"></span>Meet up #11 – Improving Silicon Halton&#8217;s Business Directory</h2>
<h3>The Topic</h3>
<p>On meet up #11, we followed the un-meeting format again:  I pitched the topic of <em>Improving the Silicon Halton&#8217;s Business Directory. </em>It proved to be a popular one attaining the most votes among all the topics suggested &#8211; and I winning me VMware t-shirt  in the process <span style="font-family:Wingdings;">J</span></p>
<h3>The Problem</h3>
<p>We are a group of IT Business in Halton region; however, there is no easy way for members or external users to find a suitable service provider within the group.</p>
<p>So the problem can be summarized as not having a useful Member Directory.  This challenge came to me when one of my projects required some development on Silverlight; my first idea was to locate a member on Silicon Halton that could partner with me to be able to provide a solution. However, I was discouraged to notice that there wasn&#8217;t a member directory that could help me with the search.</p>
<p>At the same time, I realized that other members searching for my areas of expertise would have a hard time finding my company or me…</p>
<h3>The Discussion</h3>
<p>We started the discussion re-iterating the problem: The need for a member directory: this meant that members would have to build a searchable member profile; which we haven&#8217;t done .</p>
<p>However, not all the participants felt the pressing need of a business directory; so we quickly turned into proposing ways to utilize the Linked In Group so it would serve the purpose of a business directory.</p>
<p>Some of most relevant suggestions included:</p>
<ul>
<li>Post into the boards when looking for certain expertise.</li>
<li>Create one single Discussion within the group where all the companies can post their profile. The discussion would be searchable, thus addressing the need of members to search for other members&#8217; expertise.</li>
<li>Create a Company Profile on Linked In, and join with it the Silicon Halton Group.</li>
<li>Do Job Postings on Linked In that would only apply to a Group.<br />
Note: I investigated this point, and from the initial Job Post form, it does not seem possible.</li>
</ul>
<h3><span style="font-weight:normal;font-size:13px;"><img src="https://ricardocovo.wordpress.com/wp-content/uploads/2010/09/100110_0241_improvingsi1.jpg?w=840" alt="" /></span></h3>
<h3>Conclusions</h3>
<p>These are some of the conclusions reached by the group:</p>
<ul>
<li>Linked In could be leveraged to find members by posting into the Discussion forums, improving personal profiles and creating company profiles.</li>
<li>Company members need more opportunities to present their business to the group; either on LinkedIn or at Meetings, there is a need to know what each other do, so we can find points of collaboration and be able to provide referrals.</li>
<li>While LinkedIn addresses the problems for Members, any external user/company looking for services will still encounter challenges when looking for specific providers.</li>
</ul>
<p>&#8212;</p>
<p>Thanks to everyone that participated; the creativity and resourcefulness of the members came through but certainly the problem will not go away. Although it might not be a pressing need right now, in the future Silicon Halton should consider a business directory with full profiles to be able to properly showcase and promote their members.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://ricardocovo.wordpress.com/2010/09/30/improving-silicon-halton%e2%80%99s-business-directory/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		
		<media:content url="https://0.gravatar.com/avatar/96d702c5c05363da66078eb901f3f49282ade8d99a52ea28952e666ba560c314?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ricardocovo</media:title>
		</media:content>

		<media:content url="https://ricardocovo.wordpress.com/wp-content/uploads/2010/09/100110_0241_improvingsi1.jpg" medium="image" />
	</item>
		<item>
		<title>ASP MVC – Delete confirmation with Ajax &#038; jQuery UI Dialog</title>
		<link>https://ricardocovo.wordpress.com/2010/09/02/asp-mvc-delete-confirmation-with-ajax-jquery-ui-dialog/</link>
					<comments>https://ricardocovo.wordpress.com/2010/09/02/asp-mvc-delete-confirmation-with-ajax-jquery-ui-dialog/#comments</comments>
		
		<dc:creator><![CDATA[ricardocovo]]></dc:creator>
		<pubDate>Thu, 02 Sep 2010 15:43:44 +0000</pubDate>
				<category><![CDATA[.Net Development]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[ASP.Net MVC]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[MVC]]></category>
		<guid isPermaLink="false">http://ricardocovo.wordpress.com/?p=44</guid>

					<description><![CDATA[In this post I will show you how I implemented a delete confirmation implementation for MVC using the jQuery UI Dialog control. I have done this by adding virtually no customization to the templates generated ASP.Net MVC, and aiming the functionality to be as reusable as possible. Our Objective When a user clicks the &#8220;Delete&#8221; &#8230; <a href="https://ricardocovo.wordpress.com/2010/09/02/asp-mvc-delete-confirmation-with-ajax-jquery-ui-dialog/" class="more-link">Continue reading<span class="screen-reader-text"> "ASP MVC – Delete confirmation with Ajax &#38; jQuery UI&#160;Dialog"</span></a>]]></description>
										<content:encoded><![CDATA[<p>In this post I will show you how I implemented a delete confirmation implementation for MVC using the <a href="http://jqueryui.com/demos/dialog/" target="_blank">jQuery UI Dialog</a> control. I have done this by adding virtually no customization to the templates generated ASP.Net MVC, and aiming the functionality to be as reusable as possible.</p>
<h2>Our Objective</h2>
<p>When a user clicks the &#8220;Delete&#8221; button on a list (or elsewhere), we are going to show a confirmation dialog. If the user confirms, the record will be deleted. If he/she cancels, no action will be taken. In essence, this is what we are trying to do:</p>
<p><img src="https://ricardocovo.wordpress.com/wp-content/uploads/2010/09/090210_1543_aspmvcdelet12.png?w=840" alt="" /></p>
<h2><span id="more-44"></span>Requirements</h2>
<p>To implement this solution you will need to have the <a href="http://jquery.com/" target="_blank">jQuery</a> and <a href="http://jqueryui.com/" target="_blank">jQueryUI</a> libraries.</p>
<h2>Approach</h2>
<h4>1. Modify the repeater.</h4>
<p>We will start by reviewing the code for a strongly-typed view for the &#8220;List&#8221; content; the repeater part looks like this:</p>
<p><span style="font-family:Consolas;font-size:10pt;"> <span style="background-color:yellow;">&lt;%</span> <span style="color:blue;">foreach</span> (<span style="color:blue;">var</span> item <span style="color:blue;">in</span> Model) { <span style="background-color:yellow;">%&gt;</span><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">tr</span> <span style="color:blue;"><strong> &gt;</strong></span><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">td</span><span style="color:blue;">&gt;</span><span style="background-color:yellow;">&lt;%</span><span style="color:blue;">:</span> item.Name <span style="background-color:yellow;">%&gt;</span><span style="color:blue;">&lt;/</span><span style="color:maroon;">td</span><span style="color:blue;">&gt;</span><br />
<span style="color:blue;">&lt;</span><span style="color:maroon;">td</span><span style="color:blue;">&gt;</span><br />
<span style="background-color:yellow;">&lt;%</span><span style="color:blue;">:</span> Html.ActionLink(<span style="color:#a31515;">&#8220;Edit&#8221;</span>, <span style="color:#a31515;">&#8220;Edit&#8221;</span>, <span style="color:blue;">new</span> {  id=item.Id  }) <span style="background-color:yellow;">%&gt;</span> |<br />
<span style="background-color:yellow;">&lt;%</span><span style="color:blue;">:</span> Html.ActionLink(<span style="color:#a31515;">&#8220;Delete&#8221;</span>, <span style="color:#a31515;">&#8220;Delete&#8221;</span>, <span style="color:blue;">new</span> { id = item.Id }, <strong><span style="color:blue;">new</span> { @class = <span style="color:#a31515;">&#8220;delete-link&#8221;</span> }</strong>)<span style="background-color:yellow;">%&gt;</span><br />
<span style="color:blue;">&lt;/</span><span style="color:maroon;">td</span><span style="color:blue;">&gt;</span><br />
<span style="color:blue;">&lt;/</span><span style="color:maroon;">tr</span><span style="color:blue;">&gt;</span><br />
<span style="background-color:yellow;">&lt;%</span> } <span style="background-color:yellow;">%&gt;</span><br />
</span></p>
<p>This is pretty much what is automatically generated, with the difference that I have added a class to the delete action link (bolded above). These will help me identify the object with jQuery.</p>
<p>The repeater above generates the following HTML:</p>
<pre><code><span style="font-family:Consolas;"><span style="color:maroon;">&lt;tr&gt;</span>
   <span style="color:blue;">&lt;</span><span style="color:maroon;">td</span><span style="color:blue;">&gt;</span>Item 1<span style="color:maroon;">td</span><span style="color:blue;">&gt;</span>
<span style="color:blue;">   &lt;</span><span style="color:maroon;">td</span><span style="color:blue;">&gt;
</span></span></code><span style="font-family:Consolas;"><span style="color:blue;">      &lt;</span><span style="color:maroon;">a</span> <span style="color:red;">href</span><span style="color:blue;">="/Brand/Edit/18"&gt;</span>Edit<span style="color:blue;">&lt;/</span><span style="color:maroon;">a</span><span style="color:blue;">&gt;</span> |
</span><span style="font-family:Consolas;"><span style="color:blue;">      &lt;</span><span style="color:maroon;">a</span> <span style="color:red;">class</span><span style="color:blue;">="delete-link"</span> <span style="color:red;">href</span><span style="color:blue;">="/Brand/Delete/18"&gt;</span>Delete<span style="color:blue;">&lt;/</span><span style="color:maroon;">a</span><span style="color:blue;">&gt;
</span></span><span style="font-family:Consolas;"><span style="color:blue;">    &lt;/</span><span style="color:maroon;">td</span><span style="color:blue;">&gt;
</span></span><span style="font-family:Consolas;"><span style="color:blue;">&lt;/</span><span style="color:maroon;">tr</span><span style="color:blue;">&gt;</span>    </span></pre>
<p>Notice that the Delete link is already pointing to the Controller/Action we want.</p>
<h4>2. Add the confirmation message</h4>
<p>You will need to add a <span style="color:maroon;font-family:Consolas;font-size:10pt;">div</span> tag with the confirmation message to display, simply add this:</p>
<pre><code><span style="font-family:Consolas;"><span style="color:blue;">&lt;</span><span style="color:maroon;">div</span> <span style="color:red;">id</span><span style="color:blue;">="delete-dialog"</span> <span style="color:red;">title</span><span style="color:blue;">="Confirmation"&gt;</span>
<span style="color:blue;">&lt;</span><span style="color:maroon;">p</span><span style="color:blue;">&gt;</span>Are you sure you want to delete this Brand?<span style="color:blue;">&lt;/</span><span style="color:maroon;">p</span><span style="color:blue;">&gt;</span>
<span style="color:blue;">&lt;/</span><span style="color:maroon;">div</span><span style="color:blue;">&gt;</span>		</span></code></pre>
<p>You can change the title of the confirmation box by changing the &#8220;Title&#8221; property on the <span style="color:maroon;font-family:Consolas;">div</span>.</p>
<h4>3. Add the jQuery</h4>
<p>This jQuery can be added in individual pages, in my case I added it on the Master Page so it would be reusable across many pages.</p>
<p>Let&#8217;s go by steps; first we need to override the delete link behaviour. Here is how:</p>
<pre><code><span style="font-family:Consolas;"><span style="color:blue;">var</span> deleteLinkObj;
</span></code><span style="font-family:Consolas;color:#006400;">// delete Link
</span><span style="font-family:Consolas;">$(<span style="color:maroon;">'.delete-link'</span>).click(<span style="color:blue;">function</span> () {</span>
<code><span style="font-family:Consolas;">    deleteLinkObj = $(<span style="color:blue;">this</span>);  <span style="color:darkgreen;">//for future use</span>
    $(<span style="color:maroon;">'#delete-dialog'</span>).dialog(<span style="color:maroon;">'open'</span>);
    <span style="color:blue;">return</span> <span style="color:blue;">false</span>; <span style="color:darkgreen;">// prevents the default behaviour
</span></span></code></pre>
<pre><code><span style="font-family:Consolas;">});
</span></code></pre>
<p>The snippet above is basically overriding the default functionality of all objects that have the class &#8220;delete-link&#8221;. Now, instead of directing to the specific controller/action, it will open a dialog (with ID &#8220;delete-dialog&#8221; -&gt; the <span style="font-family:Consolas;"><span style="color:maroon;">div</span> </span>we added on step 2).</p>
<p>Notice we are storing the clicked object on a variable; this is so the dialog knows which link was the one clicked.</p>
<p>Now we need to initialize the Dialog and its behaviour. Here we go:</p>
<pre><code><span style="font-family:Consolas;">$(<span style="color:maroon;">'#delete-dialog'</span>).dialog({
  autoOpen: <span style="color:blue;">false</span>, width: 400, resizable: <span style="color:blue;">false</span>, modal: <span style="color:blue;">true</span>, <span style="color:darkgreen;">//Dialog options</span>
  buttons: {
     <span style="color:maroon;">"Continue"</span>: <span style="color:blue;">function</span> () {
          $.post(deleteLinkObj [0].href, <span style="color:blue;">function</span> (data) {  <span style="color:darkgreen;">//Post to action</span>
             <span style="color:blue;">if</span> (data == <span style="color:maroon;">'</span><span style="background-color:yellow;">&lt;%</span><span style="color:blue;">=</span><span style="color:maroon;"> Boolean.TrueString </span><span style="background-color:yellow;">%&gt;</span><span style="color:maroon;">'</span>) {
                deleteLinkObj.closest(<span style="color:maroon;">"tr"</span>).hide(<span style="color:maroon;">'fast'</span>); <span style="color:darkgreen;">//Hide Row
</span></span></code><span style="font-family:Consolas;color:#006400;">                //(optional) Display Confirmation</span>
<code><span style="font-family:Consolas;">             }
             <span style="color:blue;">else</span> {
                <span style="color:darkgreen;">//(optional) Display Error</span>
             }
            });
          $(<span style="color:blue;">this</span>).dialog(<span style="color:maroon;">"close"</span>);
       },
      <span style="color:maroon;">"Cancel"</span>: <span style="color:blue;">function</span> () {
          $(<span style="color:blue;">this</span>).dialog("close");
          }
      }
 });
</span></code></pre>
<p>Let&#8217;s brake it down to the important parts:</p>
<p><span style="font-family:Consolas;"><strong>$.post(linkObj[0].href, <span style="color:blue;">function</span> (data) {&#8230;<br />
</strong></span></p>
<p>What we are doing here is posting into the objects href attribute which is something like <span style="color:blue;font-family:Consolas;">/Brand/Delete/18</span>. So we are posting to the Delete action of the Brand controller with an specific ID. The controller as we will see next, will return on the data either True or False, indicating success/failure.</p>
<p>When the post is successful, we now need to remove the item from the list. We do it with this simple line:</p>
<p><span style="font-family:Consolas;"><strong>linkObj.closest(<span style="color:maroon;">&#8220;tr&#8221;</span>).hide(<span style="color:maroon;">&#8216;fast&#8217;</span>);</strong></span></p>
<p>What we are doing is locating the closes <span style="color:maroon;font-family:Consolas;">tr</span> parent, and hiding it&#8230; Simple! (You&#8217;ve got to love jQuery).</p>
<h4>4. Prepare the controller</h4>
<p>Your page is now ready, but we need to add the logic on the controller action; there is not view related to the delete action, so you only need to implemented the <span style="color:#2b91af;font-family:Consolas;">HttpPost </span>action. This is actually very simple, in my case, here is how I do it:</p>
<pre><code><span style="font-family:Consolas;">[<span style="color:#2b91af;">HttpPost</span>]
        <span style="color:blue;">public</span> <span style="color:#2b91af;">ActionResult</span> Delete(<span style="color:blue;">int</span> id)
        {
            <span style="color:blue;">try</span>
            {
                <span style="color:#2b91af;">BrandRepostory</span> rep = <span style="color:blue;">new</span> <span style="color:#2b91af;">BrandRepostory</span> ();
                rep.DeleteById(id);
                <span style="color:blue;">return</span> Content(<span style="color:#2b91af;">Boolean</span>.TrueString);
            }
            <span style="color:blue;">catch</span>
            {</span></code><span style="font-family:Consolas;color:#006400;">//TODO: Log error</span>				
<code><span style="font-family:Consolas;">                <span style="color:blue;">return</span> Content(<span style="color:#2b91af;">Boolean</span>.FalseString);
            }
        }
</span></code></pre>
<p>That is it! This implementation is highly reusable, just remember to:</p>
<ol>
<li>Mark the delete button with the class</li>
<li>Add the <span style="color:maroon;font-family:Consolas;">div</span> for the confirmation message</li>
<li>Make sure the javascript code is available for the pages you need.</li>
<li>Implement the controller action</li>
</ol>
<p>Hope this helps.. <a href="http://www.webnodes.ca/media/4190/Demo-DeleteConfirmationDialog.zip">Get Source Code</a></p>
<p><strong>UPDATE! Related Post: </strong><a href="http://wp.me/p7vU7-1Z">Editing rows with the jQueryUI Dialog Form and Ajax</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://ricardocovo.wordpress.com/2010/09/02/asp-mvc-delete-confirmation-with-ajax-jquery-ui-dialog/feed/</wfw:commentRss>
			<slash:comments>69</slash:comments>
		
		
		
		<media:content url="https://0.gravatar.com/avatar/96d702c5c05363da66078eb901f3f49282ade8d99a52ea28952e666ba560c314?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ricardocovo</media:title>
		</media:content>

		<media:content url="https://ricardocovo.wordpress.com/wp-content/uploads/2010/09/090210_1543_aspmvcdelet12.png" medium="image" />
	</item>
	</channel>
</rss>
