<?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/"
	>

<channel>
	<title>ITmeze &#187; asp.net-mvc</title>
	<atom:link href="http://itmeze.com/tag/asp-net-mvc/feed/" rel="self" type="application/rss+xml" />
	<link>http://itmeze.com</link>
	<description>IT world served like Cyprus meze</description>
	<lastBuildDate>Thu, 07 Apr 2011 09:55:26 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>Validate max file size during upload in asp.net mvc</title>
		<link>http://itmeze.com/2011/02/20/validate-max-file-size-during-upload-in-asp-net-mvc/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=validate-max-file-size-during-upload-in-asp-net-mvc</link>
		<comments>http://itmeze.com/2011/02/20/validate-max-file-size-during-upload-in-asp-net-mvc/#comments</comments>
		<pubDate>Sun, 20 Feb 2011 22:48:27 +0000</pubDate>
		<dc:creator>ITmeze</dc:creator>
				<category><![CDATA[web development]]></category>
		<category><![CDATA[asp.net-mvc]]></category>
		<category><![CDATA[data-annotations]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://itmeze.com/?p=336</guid>
		<description><![CDATA[Just a quick sketch. Validation is done as an Attribute (DataAnotations way). public class FileAttribute : ValidationAttribute { public int MaxContentLength = int.MaxValue; public string[] AllowedFileExtensions; public string[] AllowedContentTypes; public override bool IsValid(object value) { var file = value as HttpPostedFileBase; //this should be handled by [Required] if (file == null) return true; if (file.ContentLength [...]


Related posts:<ol><li><a href='http://itmeze.com/2010/10/14/linq-enumerable-agregate-with-path-combine/' rel='bookmark' title='Permanent Link: LINQ Enumerable.Agregate with Path.Combine'>LINQ Enumerable.Agregate with Path.Combine</a></li>
<li><a href='http://itmeze.com/2010/12/06/checkbox-has-to-be-checked-with-unobtrusive-jquery-validation-and-asp-net-mvc-3/' rel='bookmark' title='Permanent Link: Checkbox has to be &#8216;checked&#8217; &#8211; with unobtrusive jQuery validation and ASP.NET MVC 3'>Checkbox has to be &#8216;checked&#8217; &#8211; with unobtrusive jQuery validation and ASP.NET MVC 3</a></li>
<li><a href='http://itmeze.com/2011/03/21/javascript-encode-on-server-side-medium-trust-environment/' rel='bookmark' title='Permanent Link: Javascript Encode on server side &#8211; Medium Trust Environment'>Javascript Encode on server side &#8211; Medium Trust Environment</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Just a quick sketch. </p>
<p>Validation is done as an Attribute (DataAnotations way).  </p>
<pre class="brush: csharp; title: ;">
 public class FileAttribute : ValidationAttribute {

        public int MaxContentLength = int.MaxValue;
        public string[] AllowedFileExtensions;
        public string[] AllowedContentTypes;

        public override bool IsValid(object value) {

            var file = value as HttpPostedFileBase;

            //this should be handled by [Required]
            if (file == null)
                return true;

            if (file.ContentLength &gt; MaxContentLength) {
                ErrorMessage = &quot;File is too large, maximum allowed is: {0} KB&quot;.FormatWith(MaxContentLength / 1024);
                return false;
            }

            if (AllowedFileExtensions != null) {
                if (!AllowedFileExtensions.Contains(file.FileName.Substring(file.FileName.LastIndexOf('.')))) {
                    ErrorMessage = &quot;Please upload file of type: &quot; + string.Join(&quot;, &quot;, AllowedFileExtensions);
                    return false;
                }
            }

            if (AllowedContentTypes != null) {
                if (!AllowedContentTypes.Contains(file.ContentType)) {
                    ErrorMessage = &quot;Please upload file of type: &quot; + string.Join(&quot;, &quot;, AllowedContentTypes);
                    return false;
                }
            }

            return true;
        }
    }
</pre>
<p>And now decorators (within viewmodel).</p>
<pre class="brush: csharp; title: ;">
[Display(Name = &quot;Upload Proof of Address&quot;)]
[File(AllowedFileExtensions = new string[] { &quot;.jpg&quot;, &quot;.gif&quot;, &quot;.tiff&quot;, &quot;.png&quot;, &quot;.pdf&quot; }, MaxContentLength = 1024 * 1024 * 8, ErrorMessage = &quot;Invalid File&quot;)]
public HttpPostedFileBase AddressProof { get; set; }
</pre>
<p>Hope that helps someone.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fitmeze.com%2F2011%2F02%2F20%2Fvalidate-max-file-size-during-upload-in-asp-net-mvc%2F&amp;title=Validate%20max%20file%20size%20during%20upload%20in%20asp.net%20mvc"><img src="http://itmeze.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>

<p>Related posts:<ol><li><a href='http://itmeze.com/2010/10/14/linq-enumerable-agregate-with-path-combine/' rel='bookmark' title='Permanent Link: LINQ Enumerable.Agregate with Path.Combine'>LINQ Enumerable.Agregate with Path.Combine</a></li>
<li><a href='http://itmeze.com/2010/12/06/checkbox-has-to-be-checked-with-unobtrusive-jquery-validation-and-asp-net-mvc-3/' rel='bookmark' title='Permanent Link: Checkbox has to be &#8216;checked&#8217; &#8211; with unobtrusive jQuery validation and ASP.NET MVC 3'>Checkbox has to be &#8216;checked&#8217; &#8211; with unobtrusive jQuery validation and ASP.NET MVC 3</a></li>
<li><a href='http://itmeze.com/2011/03/21/javascript-encode-on-server-side-medium-trust-environment/' rel='bookmark' title='Permanent Link: Javascript Encode on server side &#8211; Medium Trust Environment'>Javascript Encode on server side &#8211; Medium Trust Environment</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://itmeze.com/2011/02/20/validate-max-file-size-during-upload-in-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Client side validation after Ajax Partial View result in ASP.NET MVC 3</title>
		<link>http://itmeze.com/2010/10/08/client-side-validation-after-ajax-partial-view-result-in-asp-net-mvc-3/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=client-side-validation-after-ajax-partial-view-result-in-asp-net-mvc-3</link>
		<comments>http://itmeze.com/2010/10/08/client-side-validation-after-ajax-partial-view-result-in-asp-net-mvc-3/#comments</comments>
		<pubDate>Fri, 08 Oct 2010 20:59:42 +0000</pubDate>
		<dc:creator>ITmeze</dc:creator>
				<category><![CDATA[web development]]></category>
		<category><![CDATA[asp.net-mvc]]></category>
		<category><![CDATA[client side validation]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[unobtrusive javascript]]></category>

		<guid isPermaLink="false">http://itmeze.com/?p=290</guid>
		<description><![CDATA[Now, as ASP.NET MVC 3 beta was finally released I have decided to give it a try. The most exciting thing that I have noticed is implementation of an idea of so called Unobtrusive JavaScript. This is for both Ajax helpers and Client Validation. And I have to admit that I just love it. I [...]


Related posts:<ol><li><a href='http://itmeze.com/2009/08/13/tips-for-jquery-validation-plugin/' rel='bookmark' title='Permanent Link: Tips for jQuery validation plugin'>Tips for jQuery validation plugin</a></li>
<li><a href='http://itmeze.com/2010/12/06/checkbox-has-to-be-checked-with-unobtrusive-jquery-validation-and-asp-net-mvc-3/' rel='bookmark' title='Permanent Link: Checkbox has to be &#8216;checked&#8217; &#8211; with unobtrusive jQuery validation and ASP.NET MVC 3'>Checkbox has to be &#8216;checked&#8217; &#8211; with unobtrusive jQuery validation and ASP.NET MVC 3</a></li>
<li><a href='http://itmeze.com/2009/07/21/firefox-3-0-411-length-required-with-jquery/' rel='bookmark' title='Permanent Link: Firefox 3.0: 411 Length required with JQuery'>Firefox 3.0: 411 Length required with JQuery</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"><!--
google_ad_client = "pub-7051816622200841";
google_ad_slot = "0915606426";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
<p>Now, as ASP.NET MVC 3 beta was finally released I have decided to give it a try.</p>
<p>The most exciting thing that I have noticed is implementation of an idea of so called <a href="http://en.wikipedia.org/wiki/Unobtrusive_JavaScript">Unobtrusive JavaScript</a>. This is for both Ajax helpers and Client Validation. And I have to admit that I just love it.</p>
<p>I wll just copy and paste text from scottgu blog:</p>
<blockquote><p><strong>Unobtrusive JavaScript and HTML 5</strong>: The AJAX and Validation helpers in ASP.NET MVC now both use an <a href="http://en.wikipedia.org/wiki/Unobtrusive_JavaScript" target="_blank">unobtrusive JavaScript</a> approach by default. Unobtrusive JavaScript avoid injecting inline JavaScript into HTML, and instead enables cleaner separation of behavior using the new HTML 5 data- convention (which conveniently works on older browsers as well). This makes your HTML smaller and cleaner, and makes it easier to optionally swap out or customize JS libraries.  The Validation helpers in ASP.NET MVC 3 also now use the jQueryValidate plugin by default.</p></blockquote>
<p>Basically we get all the validation done by loading js function parsing loaded DOM searching for specific parameters based on which validation rules are applied to elements. And all of that without a single js line from &#8216;our&#8217; &#8211; web developers side.</p>
<p>One thing is not obvious though and it certainly needs extra explanation: what happens after part of the page is loaded via Ajax request (common Partial View result). Validation is not turned for those elements although all attributes are correctly marked. I have dig a little and found within JavaScript file &#8216;jquery.validate.unobtrusive.js&#8217; function: jQuery.validator.unobtrusive.parse(selector). Calling function after new content is loaded solves problem, like in the example below:</p>
<pre class="brush: jscript; title: ;">

$.post(&quot;test/updateCustomer&quot;, { name: &quot;Mark&quot;, surname: &quot;Barker&quot; },
  function(htmlContent){
    $('#container').html(htmlContent);
    jQuery.validator.unobtrusive.parse('#content')
  }
);
</pre>
<p>Hope it helps someone&#8230;</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fitmeze.com%2F2010%2F10%2F08%2Fclient-side-validation-after-ajax-partial-view-result-in-asp-net-mvc-3%2F&amp;title=Client%20side%20validation%20after%20Ajax%20Partial%20View%20result%20in%20ASP.NET%20MVC%203"><img src="http://itmeze.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>

<p>Related posts:<ol><li><a href='http://itmeze.com/2009/08/13/tips-for-jquery-validation-plugin/' rel='bookmark' title='Permanent Link: Tips for jQuery validation plugin'>Tips for jQuery validation plugin</a></li>
<li><a href='http://itmeze.com/2010/12/06/checkbox-has-to-be-checked-with-unobtrusive-jquery-validation-and-asp-net-mvc-3/' rel='bookmark' title='Permanent Link: Checkbox has to be &#8216;checked&#8217; &#8211; with unobtrusive jQuery validation and ASP.NET MVC 3'>Checkbox has to be &#8216;checked&#8217; &#8211; with unobtrusive jQuery validation and ASP.NET MVC 3</a></li>
<li><a href='http://itmeze.com/2009/07/21/firefox-3-0-411-length-required-with-jquery/' rel='bookmark' title='Permanent Link: Firefox 3.0: 411 Length required with JQuery'>Firefox 3.0: 411 Length required with JQuery</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://itmeze.com/2010/10/08/client-side-validation-after-ajax-partial-view-result-in-asp-net-mvc-3/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Getting ugly with BeginActionLink helper!</title>
		<link>http://itmeze.com/2010/06/25/getting-ugly-with-beginactionlink-helper/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=getting-ugly-with-beginactionlink-helper</link>
		<comments>http://itmeze.com/2010/06/25/getting-ugly-with-beginactionlink-helper/#comments</comments>
		<pubDate>Sat, 26 Jun 2010 00:13:41 +0000</pubDate>
		<dc:creator>ITmeze</dc:creator>
				<category><![CDATA[web development]]></category>
		<category><![CDATA[actionlink]]></category>
		<category><![CDATA[asp.net-mvc]]></category>
		<category><![CDATA[htmlhelpers]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://itmeze.com/?p=271</guid>
		<description><![CDATA[Have You ever had such a moment when the most stupid and trivial solution turns out to be the ONLY ONE that is logically suitable at the moment? When I had such a feeling today&#8230;. I am working on a module for one of huge web portals (not to mention which one). Part of that [...]


Related posts:<ol><li><a href='http://itmeze.com/2010/10/16/how-to-implementing-log-in-to-site-with-facebook-account-in-asp-net-mvc/' rel='bookmark' title='Permanent Link: How to implementing log in to site with Facebook account in ASP.NET MVC'>How to implementing log in to site with Facebook account in ASP.NET MVC</a></li>
<li><a href='http://itmeze.com/2011/02/20/validate-max-file-size-during-upload-in-asp-net-mvc/' rel='bookmark' title='Permanent Link: Validate max file size during upload in asp.net mvc'>Validate max file size during upload in asp.net mvc</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Have You ever had such a moment when the most stupid and trivial solution turns out to be the ONLY ONE that is logically suitable at the moment? When I had such a feeling today&#8230;.<br />
I am working on a module for one of huge web portals (not to mention which one). Part of that module is only accessible to users with administration permissions &#8211; as typical as it can be. The reason why I am mentioning that is to highlight the fact that at this specific part performance does not matter so much. Anyway, my talk to one of designers (Friday, half an hour before &#8216;the beginning of the weekend&#8217;):<br />
<strong> </strong></p>
<p><strong>Designer: </strong>I am going to spend whole weekend on those Views&#8230;</p>
<p><strong>Me: </strong>Yeah&#8230; S*** happens&#8230;.</p>
<p><strong>Designer: </strong>Those &#8216;Html.ActionLink&#8217; that You use everywhere, how do I put something inside, you know, images, spans, staff like that&#8230;</p>
<p><strong>Me: </strong>Argh&#8230; Hm&#8230;..</p>
<p>I suddenly realize that before I leave the office this guy needs an extension method: <strong>BeginActionLink </strong>like right now!. The similar one that is used for Forms elements (BeginForm). Then I started to code&#8230; Have You ever realized that ActionLink has roughly 12 overloads!!!! That would take hours to prepare BeginActionLink for most of them.</p>
<p><a href="http://itmeze.com/wp-content/uploads/2010/06/idea-bulb.jpg"><img class="alignleft size-thumbnail wp-image-275" style="margin: 10px;" title="idea" src="http://itmeze.com/wp-content/uploads/2010/06/idea-bulb-150x150.jpg" alt="idea bulb" width="150" height="150" /></a></p>
<p>When You are blocked, what You do? Me too, I started &#8216;googling&#8217;. Nothing simple and smart enough. Except 200 lines of code with tons of overloads&#8230; argh&#8230;</p>
<p>But then, completely unexpectedly &#8230;.</p>
<p>My moment of genius!</p>
<p>Don&#8217;t laugh! For people over &#8230; some age &#8230; that things do not happen offen! <img src='http://itmeze.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>There are solutions that developers are ashamed of, but they simply do their job:</p>
<pre class="brush: csharp; title: ;">public static string TrimEndTag(this MvcHtmlString htmlString, string tagName = &quot;a&quot;)
        {
            var endTag = new TagBuilder(tagName).ToString(TagRenderMode.EndTag); 

            var tagString = htmlString.ToString();

            var endTagIndex = tagString.LastIndexOf(endTag);

            if(endTagIndex &gt; 0)
                tagString = tagString.Remove(endTagIndex).TrimEnd();

            return tagString;
        }

        public static string ToEndTag(this HtmlHelper html, string tagName)
        {
            return new TagBuilder(tagName).ToString(TagRenderMode.EndTag);
        }</pre>
<p>I am simply removing end tag from ActionLink returned string! As simple as that! So all that is left for my buddy to do is to use it like that:</p>
<pre class="brush: csharp; title: ;">&lt;%= Html.ActionLink(&quot; &quot;, &quot;testAction&quot;, &quot;testController&quot;, new { id = 4 }, new {}).TrimEndTag() %&gt;

        images, spans, text, whatever...

    &lt;%= Html.ToEndTag(&quot;a&quot;) %&gt;</pre>
<p>Wuala! Ugly, So ugly, but at the same time I am preserving original methods for ActionLinks and I couldn&#8217;t figure out better solution&#8230;.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fitmeze.com%2F2010%2F06%2F25%2Fgetting-ugly-with-beginactionlink-helper%2F&amp;title=Getting%20ugly%20with%20BeginActionLink%20helper%21"><img src="http://itmeze.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>

<p>Related posts:<ol><li><a href='http://itmeze.com/2010/10/16/how-to-implementing-log-in-to-site-with-facebook-account-in-asp-net-mvc/' rel='bookmark' title='Permanent Link: How to implementing log in to site with Facebook account in ASP.NET MVC'>How to implementing log in to site with Facebook account in ASP.NET MVC</a></li>
<li><a href='http://itmeze.com/2011/02/20/validate-max-file-size-during-upload-in-asp-net-mvc/' rel='bookmark' title='Permanent Link: Validate max file size during upload in asp.net mvc'>Validate max file size during upload in asp.net mvc</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://itmeze.com/2010/06/25/getting-ugly-with-beginactionlink-helper/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ASP.NET MVC 2 Preview 1 released!</title>
		<link>http://itmeze.com/2009/07/31/asp-net-mvc-2-preview-1-released/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=asp-net-mvc-2-preview-1-released</link>
		<comments>http://itmeze.com/2009/07/31/asp-net-mvc-2-preview-1-released/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 11:36:44 +0000</pubDate>
		<dc:creator>ITmeze</dc:creator>
				<category><![CDATA[web development]]></category>
		<category><![CDATA[asp.net-mvc]]></category>

		<guid isPermaLink="false">http://itmeze.com/?p=59</guid>
		<description><![CDATA[YES! YES! YES! Great news for all MVC lovers, check it out on Phil&#8217;s blog Related posts:My first words!


Related posts:<ol><li><a href='http://itmeze.com/2009/04/24/my-first-words/' rel='bookmark' title='Permanent Link: My first words!'>My first words!</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p><script type="text/javascript"><!--
google_ad_client = "pub-7051816622200841";
google_ad_slot = "0915606426";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</p>
<p>YES! YES! YES!</p>
<p>Great news for all MVC lovers, check it out on <a href="http://haacked.com/archive/2009/07/30/asp.net-mvc-released.aspx">Phil&#8217;s blog</a></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fitmeze.com%2F2009%2F07%2F31%2Fasp-net-mvc-2-preview-1-released%2F&amp;title=ASP.NET%20MVC%202%20Preview%201%20released%21"><img src="http://itmeze.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>

<p>Related posts:<ol><li><a href='http://itmeze.com/2009/04/24/my-first-words/' rel='bookmark' title='Permanent Link: My first words!'>My first words!</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://itmeze.com/2009/07/31/asp-net-mvc-2-preview-1-released/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

