<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:blogChannel="http://backend.userland.com/blogChannelModule" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
  <channel>
    <title>naspinski</title>
    <description>development :: programming :: design</description>
    <link>http://naspinski.net/</link>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>BlogEngine.Net Syndication Generator 1.0.0.0 (http://dotnetblogengine.net/)</generator>
    <language>en-GB</language>
    <blogChannel:blogRoll>http://naspinski.net/opml.axd</blogChannel:blogRoll>
    <blogChannel:blink>http://www.naspinski.net/syndication.axd</blogChannel:blink>
    <dc:creator>naspinski</dc:creator>
    <dc:title>naspinski</dc:title>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/naspinski" /><feedburner:info uri="naspinski" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
      <title>jQuery moveTo() plugin</title>
      <description>&lt;h2&gt;simple way to move an element from A to B&lt;/h2&gt;
Say you have these elements:
&lt;pre class="prettyprint"&gt;&amp;lt;ul id="A"&amp;gt;
    &amp;lt;li id="L1"&amp;gt;Stan&amp;lt;/li&amp;gt;
    &amp;lt;li id="L2"&amp;gt;Arnold&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;
&amp;lt;ul id="B"&amp;gt;
&amp;lt;/ul&amp;gt;&lt;/pre&gt;
&lt;br /&gt;
And you want to move 'L1' (Stan) to ul 'B' - using this simple short plugin:
&lt;pre class="prettyprint"&gt;(function ($) {
    $.fn.moveTo = function (selector) {
        return this.each(function () {
            var element = $(this).detach();
            $(selector).append(element);
        });
    };
})(jQuery);&lt;/pre&gt;
&lt;br /&gt;
You can do that with this:
&lt;pre class="prettyprint"&gt;$('#L1').moveTo('#B');&lt;/pre&gt;
&lt;br /&gt;
Now you have this in your DOM:
&lt;pre class="prettyprint"&gt;&amp;lt;ul id="A"&amp;gt;
    &amp;lt;li id="L2"&amp;gt;Arnold&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;
&amp;lt;ul id="B"&amp;gt;
    &amp;lt;li id="L1"&amp;gt;Stan&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;&lt;/pre&gt;
&lt;br /&gt;
Or, similarly, you can do something like this:
&lt;pre class="prettyprint"&gt;$('li').moveTo('#B');&lt;/pre&gt;
&lt;br /&gt;
Now you have this in your DOM:
&lt;pre class="prettyprint"&gt;&amp;lt;ul id="A"&amp;gt;
&amp;lt;/ul&amp;gt;
&amp;lt;ul id="B"&amp;gt;
    &amp;lt;li id="L1"&amp;gt;Stan&amp;lt;/li&amp;gt;
    &amp;lt;li id="L2"&amp;gt;Arnold&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;&lt;/pre&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=5oteMahpHYs:5_kQw1XXtSc:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=5oteMahpHYs:5_kQw1XXtSc:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=5oteMahpHYs:5_kQw1XXtSc:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=5oteMahpHYs:5_kQw1XXtSc:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=5oteMahpHYs:5_kQw1XXtSc:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/5oteMahpHYs" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/5oteMahpHYs/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/jQuery-moveTo()-plugin.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=fe59b0eb-1b07-470b-be33-0bd09a172492</guid>
      <pubDate>Wed, 06 Feb 2013 15:26:00 -0400</pubDate>
      <category>javascript</category>
      <category>jquery</category>
      <category>steal some code</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=fe59b0eb-1b07-470b-be33-0bd09a172492</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=fe59b0eb-1b07-470b-be33-0bd09a172492</trackback:ping>
      <wfw:comment>http://naspinski.net/post/jQuery-moveTo()-plugin.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=fe59b0eb-1b07-470b-be33-0bd09a172492</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=fe59b0eb-1b07-470b-be33-0bd09a172492</feedburner:origLink></item>
    <item>
      <title>Double Input problem with CheckBoxFor in MVC while serializing</title>
      <description>&lt;h2&gt;if you have tried to serialize a CheckBoxFor from MVC to JSON, you will notice that you get two inputs, and it can mess up the data you are sending&lt;/h2&gt;

It's no surprise that JavaScript is not sure how MVC works so when you try &lt;string&gt;data.serialize()&lt;/strong&gt; on MVC form data, you get odd results.  Here is a simple workaround for when you need something to be serialized.  I modified the GetPropertyName method from &lt;a href="http://stackoverflow.com/questions/671968/retrieving-property-name-from-lambda-expression"&gt;this post on StackOverflow&lt;/a&gt;.

&lt;pre class="prettyprint"&gt;public static string GetPropertyName&amp;lt;TModel, TValue&amp;gt;
    (Expression&lt;Func&lt;TModel, TValue&gt;&gt; exp)
{
    MemberExpression body = exp.Body as MemberExpression;
    if (body == null)
    {
        UnaryExpression ubody = (UnaryExpression)exp.Body;
        body = ubody.Operand as MemberExpression;
    }
    return body.Member.Name;
}

public static MvcHtmlString CheckBoxForJson&amp;lt
    ;TModel, TValue&amp;gt;(this HtmlHelper&amp;lt;TModel&amp;gt; helper, 
    Expression&amp;lt;Func&amp;lt;TModel, TValue&amp;gt;&amp;gt; expression)
{
    string propName = GetPropertyName(expression);
    string html = "&amp;lt;input type=\"checkbox\" name=\"" 
        + propName + "\" id=\"" 
        + propName + "\" value=\"true\" /&amp;gt;";
    return MvcHtmlString.Create(html);
}&lt;/pre&gt;
&lt;br /&gt;
And use it like this:
&lt;pre class="prettyprint"&gt;@Html.CheckBoxForJson(x =&amp;gt; x.SomeBool)&lt;/pre&gt;
&lt;br /&gt;
The reason for the 'true' is because otherwise it will always pass as false since 'on' is not a bool value (html default).&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=hKt4WWTJ0G0:T2BIxfBd1B8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=hKt4WWTJ0G0:T2BIxfBd1B8:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=hKt4WWTJ0G0:T2BIxfBd1B8:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=hKt4WWTJ0G0:T2BIxfBd1B8:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=hKt4WWTJ0G0:T2BIxfBd1B8:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/hKt4WWTJ0G0" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/hKt4WWTJ0G0/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/Double-Input-problem-with-CheckBoxFor-in-MVC-while-serializing.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=5f616bbe-5d24-4905-bb92-e611a6175e07</guid>
      <pubDate>Fri, 25 Jan 2013 14:44:00 -0400</pubDate>
      <category>asp.net</category>
      <category>c#</category>
      <category>mvc</category>
      <category>steal some code</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=5f616bbe-5d24-4905-bb92-e611a6175e07</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=5f616bbe-5d24-4905-bb92-e611a6175e07</trackback:ping>
      <wfw:comment>http://naspinski.net/post/Double-Input-problem-with-CheckBoxFor-in-MVC-while-serializing.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=5f616bbe-5d24-4905-bb92-e611a6175e07</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=5f616bbe-5d24-4905-bb92-e611a6175e07</feedburner:origLink></item>
    <item>
      <title>Print your javascript object</title>
      <description>&lt;h2&gt;nothing revolutionary, just helpful in some debug situations&lt;/h2&gt;
&lt;pre class="prettyprint"&gt;alert(JSON.stringify(data, null, 4));&lt;/pre&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=ilFWIOVGa8U:KYlJLivol2M:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=ilFWIOVGa8U:KYlJLivol2M:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=ilFWIOVGa8U:KYlJLivol2M:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=ilFWIOVGa8U:KYlJLivol2M:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=ilFWIOVGa8U:KYlJLivol2M:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/ilFWIOVGa8U" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/ilFWIOVGa8U/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/Print-your-javascript-object.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=06924b6f-c060-446e-b0c9-0d1d76e5f26a</guid>
      <pubDate>Fri, 07 Dec 2012 16:53:00 -0400</pubDate>
      <category>javascript</category>
      <category>steal some code</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=06924b6f-c060-446e-b0c9-0d1d76e5f26a</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=06924b6f-c060-446e-b0c9-0d1d76e5f26a</trackback:ping>
      <wfw:comment>http://naspinski.net/post/Print-your-javascript-object.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=06924b6f-c060-446e-b0c9-0d1d76e5f26a</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=06924b6f-c060-446e-b0c9-0d1d76e5f26a</feedburner:origLink></item>
    <item>
      <title>Naspinski.Utilities now on NuGet</title>
      <description>&lt;h2&gt;Utilities class for .Net including Dynamic property getters/setters, automatic IQueryable searching, LinqToSql shortcuts, FileStream shortcuts, String extensions and more&lt;/h2&gt;

This is a utility class that was developed with the help of others that I use in almost all of my .Net projects.  It is available &lt;a href="http://nuget.org/packages/Naspinski.Utilities"&gt;via NuGet&lt;/a&gt; as well as on &lt;a href="http://naspinski.codeplex.com/"&gt;CodePlex&lt;/a&gt;. It includes:
&lt;br /&gt;&lt;br /&gt;

&lt;h4&gt;DynamicProperty&lt;/h4&gt;
Change a property value at run time without knowing the property ahead of time:
&lt;pre class="prettyprint"&gt;someObject.SetPropertyValue("Name", "new value")
// is the same as 
someObject.Name = "new value";
// no need to know which property to code in&lt;/pre&gt;
&lt;br /&gt;
&lt;a href="http://www.naspinski.net/post/Edit-an-Object-Property-Value-Dynamically-at-Runtime.aspx"&gt;More Information&lt;/a&gt;
&lt;br /&gt;&lt;br /&gt;


&lt;h4&gt;IQueryableSearch&lt;/h4&gt;
Search all/any properties of an IQueryable with one single search.
&lt;br /&gt;&lt;br /&gt;
The 'quick search' is a great tool. Google has shown us that searching with one single, universal search field is the way that people prefer to search. Anyone who has worked with Linq for any amount of time knows this is possible, but it requires a lot of hard-coding and a long jumble of 'where' statements. This class will allow you to run a universal 'google-like' search on any IQueryable.
&lt;a href="http://naspinski.net/post/Universal-IQueryable-Search-Version-2-with-Reflection.aspx"&gt;More Information&lt;/a&gt;
&lt;pre class="prettyprint"&gt;var results = cars.Search(new object[] {"chevy", 2007});
// will search cars for the string "chevy" 
// and the int 2007 across all fields&lt;/pre&gt;
&lt;br /&gt;&lt;br /&gt;

&lt;h4&gt;LinqToSql&lt;/h4&gt;
Universal Get Extensions for your DataContexts, Find the Primary Key of any table, and more

&lt;pre class="prettyprint"&gt;Naspinski.Utilities.GetPrimaryKey&amp;lt;table&amp;gt;();
// will return the PropertyInfo of the Primary Key(s) of 'table'

someDataContext.Get&amp;lt;Car&amp;gt;(someKey); 
// is the same as writing:
someDataContext.Cars.FirstOrDefault(x =&amp;gt; x.id == someKey);
// regardless of what Type someKey is or what the 
// PropertyInfo.Name of the Primary Key is; never write 
// a Get accessor again!&lt;/pre&gt;

&lt;h4&gt;FileStreamSave&lt;/h4&gt;
Simple extension to save a FileStream to disk, option to avoid overwriting will automatically update the filename to avoid overwriting:
&lt;pre class="prettyprint"&gt;someFileStream.Save(@"C:\file.txt")
// will save the file to the given path
// 'file[1].txt' if the file is already there 
// the file name will be returned 

someFileStream.Save(@"C:\file.txt", false);
// will save the file to the given path,
// overwriting if the file already exists&lt;/pre&gt;

&lt;h4&gt;StringConversions&lt;/h4&gt;
Convert strings to things you often need to convert them to, easily.
&lt;pre class="prettyprint"&gt;string s = s.RemoveCharacters(new[] { 'a', 'b' })
// removes any instances of 'a' or 'b' from s

string s = Strings.Random(10)
// random string, all alphanumeric, length 10
string s = Strings.Random(10, 2)
// random string, min 2 special chars, length 10

double x = "8".To&amp;lt;double&amp;gt;; 
// converts string to any type 
// (double in this case)

EnumType et = "Something".ToEnum&amp;lt;EnumType&amp;gt;; 
// turns string into any enum 
// (EnumType.Something in this case)

int? x = "5".ToNullable&amp;lt;int&amp;gt;;
// turns a string into any Nullable Type you want 
// (int in this case)&lt;/pre&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=xpiOA_F_j8Q:TLR3RqvCpM0:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=xpiOA_F_j8Q:TLR3RqvCpM0:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=xpiOA_F_j8Q:TLR3RqvCpM0:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=xpiOA_F_j8Q:TLR3RqvCpM0:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=xpiOA_F_j8Q:TLR3RqvCpM0:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/xpiOA_F_j8Q" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/xpiOA_F_j8Q/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/NaspinskiUtilities.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=eca55c72-6e4f-410d-b75f-273376f9687c</guid>
      <pubDate>Sat, 20 Oct 2012 17:03:00 -0400</pubDate>
      <category>c#</category>
      <category>linq</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=eca55c72-6e4f-410d-b75f-273376f9687c</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=eca55c72-6e4f-410d-b75f-273376f9687c</trackback:ping>
      <wfw:comment>http://naspinski.net/post/NaspinskiUtilities.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=eca55c72-6e4f-410d-b75f-273376f9687c</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=eca55c72-6e4f-410d-b75f-273376f9687c</feedburner:origLink></item>
    <item>
      <title>MVC Html Helper for including an Id with a DisplayFor</title>
      <description>&lt;h2&gt;there are cases when you want to include an id with your DisplayFor()&lt;/h2&gt;

&lt;pre class="prettyprint"&gt;public static MvcHtmlString DisplayWithIdFor&lt;TModel, TValue&gt;(
    this HtmlHelper&lt;TModel&gt; helper, 
    Expression&lt;Func&lt;TModel, TValue&gt;&gt; expression, 
    string wrapperTag = "div")
{
    var id = helper.ViewContext.ViewData.TemplateInfo
        .GetFullHtmlFieldId(ExpressionHelper
            .GetExpressionText(expression));
    return MvcHtmlString.Create(
        string.Format("&lt;{0} id=\"{1}\"&gt;{2}&lt;/{0}&gt;", wrapperTag, 
        id, helper.DisplayFor(expression)));
}&lt;/pre&gt;
&lt;br /&gt;
It is used like this:
&lt;pre class="prettyprint"&gt;@Html.DisplayWithIdFor(x =&gt; x.Name)
&amp;lt;!-- to produce --&amp;gt;
&amp;lt;div id="Name"&amp;gt;Bill&amp;lt;/div&amp;gt;&lt;/pre&gt;
&lt;br /&gt;

Or if you want to wrap it in a non-div:
&lt;pre class="prettyprint"&gt;@Html.DisplayWithIdFor(x =&gt; x.Name, "span")
&amp;lt;!-- to produce: --&amp;gt;
&amp;lt;span id="Name"&amp;gt;Bill&amp;lt;/span&amp;gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=XpLcNfTtPaA:RTJtWvqAwHU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=XpLcNfTtPaA:RTJtWvqAwHU:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=XpLcNfTtPaA:RTJtWvqAwHU:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=XpLcNfTtPaA:RTJtWvqAwHU:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=XpLcNfTtPaA:RTJtWvqAwHU:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/XpLcNfTtPaA" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/XpLcNfTtPaA/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/MVC-Html-Helper-for-including-an-Id-with-a-DisplayFor.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=6499d52d-8fff-43c4-9ac4-36ea3c869338</guid>
      <pubDate>Thu, 18 Oct 2012 17:29:00 -0400</pubDate>
      <category>asp.net</category>
      <category>c#</category>
      <category>mvc</category>
      <category>steal some code</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=6499d52d-8fff-43c4-9ac4-36ea3c869338</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=6499d52d-8fff-43c4-9ac4-36ea3c869338</trackback:ping>
      <wfw:comment>http://naspinski.net/post/MVC-Html-Helper-for-including-an-Id-with-a-DisplayFor.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=6499d52d-8fff-43c4-9ac4-36ea3c869338</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=6499d52d-8fff-43c4-9ac4-36ea3c869338</feedburner:origLink></item>
    <item>
      <title>Quick LINQ Trick</title>
      <description>&lt;h2&gt;cool way to shorten and make your code more readable with LINQ&lt;/h2&gt;

Say I have this function:
&lt;pre class="prettyprint"&gt;public string DoStuff(string s) 
{ 
    //whole bunch of stuff
    return s; 
}&lt;/pre&gt;
&lt;br /&gt;
Now say I have the following:
&lt;pre class="prettyprint"&gt;public IEnumerable&lt;string&gt; DoThings(IEnumerable&lt;string&gt; strs) 
{  
    var ret = new list&lt;string&gt;();
    foreach(var s in strs)
        ret.Add(DoStuff(s));
    return ret;
}&lt;/pre&gt;
&lt;br /&gt;
Which can be reduced to:
&lt;pre class="prettyprint"&gt;public IEnumerable&lt;string&gt; DoThings(IEnumerable&lt;string&gt; strs) 
{  
    foreach(var s in strs)
        yield return DoStuff(s);
}&lt;/pre&gt;
&lt;br /&gt;
Or...
&lt;pre class="prettyprint"&gt;public IEnumerable&lt;string&gt; DoThings(IEnumerable&lt;string&gt; strs) 
{  
    strs.Select(x =&gt; DoStuff(x));
}&lt;/pre&gt;
&lt;br /&gt;
but even further you can simply take it to:
&lt;pre class="prettyprint"&gt;public IEnumerable&lt;string&gt; DoThings(IEnumerable&lt;string&gt; strs) 
{  
    strs.Select(DoStuff);
}&lt;/pre&gt;
&lt;br /&gt;
Since the enumeration is already strings, the Select statement knows just to pass them through the method supplied. With it this small, the method is almost useless to write out:
&lt;pre class="prettyprint"&gt;// Tnstead of:
var x = DoThings(strs);

// you can simply substitute: 
var y = strs.Select(DoStuff);

// giving you the same results without having to write 
// a method&lt;/pre&gt;
&lt;br /&gt;
It's nothing revolutionary, but can clean up your code where applicable.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=9p9yFexOKkU:yXkgWzjY6S4:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=9p9yFexOKkU:yXkgWzjY6S4:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=9p9yFexOKkU:yXkgWzjY6S4:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=9p9yFexOKkU:yXkgWzjY6S4:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=9p9yFexOKkU:yXkgWzjY6S4:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/9p9yFexOKkU" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/9p9yFexOKkU/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/Quick-LINQ-Trick.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=4e0ecf7f-faca-47f8-a952-c57b3d9d7d76</guid>
      <pubDate>Tue, 18 Sep 2012 16:21:00 -0400</pubDate>
      <category>c#</category>
      <category>linq</category>
      <category>steal some code</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=4e0ecf7f-faca-47f8-a952-c57b3d9d7d76</pingback:target>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=4e0ecf7f-faca-47f8-a952-c57b3d9d7d76</trackback:ping>
      <wfw:comment>http://naspinski.net/post/Quick-LINQ-Trick.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=4e0ecf7f-faca-47f8-a952-c57b3d9d7d76</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=4e0ecf7f-faca-47f8-a952-c57b3d9d7d76</feedburner:origLink></item>
    <item>
      <title>Random String Generator in C#</title>
      <description>&lt;h2&gt;produce random string simply in .net, without special characters if need be&lt;/h2&gt;
It is very simple to get random string since the introduction of &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.security.membership.generatepassword.aspx"&gt;Membership.GeneratePassword()&lt;/a&gt; - so this really just a way to utilize that and pull out special characters if that is what you are looking for.

&lt;pre class="prettyprint"&gt;public static string ToRandomString(this string s, 
    int length, bool isOnlyAlphaNumeric = true, 
    int minSpecialCharacters = 1)
{
    if (isOnlyAlphaNumeric) minSpecialCharacters = 0;
    s = Membership
        .GeneratePassword(length, minSpecialCharacters);
    if (!isOnlyAlphaNumeric) return s;
            
    char[] msSpecialCharacters = 
        "!@#$%^&amp;*()_-+=[{]};:&lt;&gt;|./?".ToCharArray();
    string filler = 
        Membership.GeneratePassword(length, 0);
    int fillerIndex = 0;
    int fillerBuffer = 0;

    while(s.IndexOfAny(msSpecialCharacters) &gt; -1 
        || s.Length &lt; length)
    {
        s = s.RemoveCharacters(msSpecialCharacters);
        fillerBuffer =length - s.Length;
        if((fillerBuffer + fillerIndex) &gt; filler.Length)
        {   // filler would out-of-bounds, get a new one
            filler = 
                Membership.GeneratePassword(length, 0);
            fillerIndex = 0;
        }
        s += filler.Substring(fillerIndex, fillerBuffer);
        fillerIndex += fillerBuffer;
    }
    return s;
}

public static string RemoveCharacters
    (this string s, char[] characters)
{
    return new string(s.ToCharArray()
        .Where(c =&gt; !characters.Contains(c)).ToArray());
}&lt;/pre&gt;
&lt;br /&gt;
This has been added to my &lt;a href="http://naspinski.codeplex.com/"&gt;Naspinski.Utilities&lt;/a&gt; library, though it isn't released just yet, looking to tweak it a bit first.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=RO_wnLO_DQY:J8xDEMPogOE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=RO_wnLO_DQY:J8xDEMPogOE:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=RO_wnLO_DQY:J8xDEMPogOE:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=RO_wnLO_DQY:J8xDEMPogOE:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=RO_wnLO_DQY:J8xDEMPogOE:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/RO_wnLO_DQY" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/RO_wnLO_DQY/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/RandomString.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=0c201179-6560-46db-a97a-70f5bdd63b02</guid>
      <pubDate>Fri, 14 Sep 2012 15:23:00 -0400</pubDate>
      <category>c#</category>
      <category>steal some code</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=0c201179-6560-46db-a97a-70f5bdd63b02</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=0c201179-6560-46db-a97a-70f5bdd63b02</trackback:ping>
      <wfw:comment>http://naspinski.net/post/RandomString.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=0c201179-6560-46db-a97a-70f5bdd63b02</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=0c201179-6560-46db-a97a-70f5bdd63b02</feedburner:origLink></item>
    <item>
      <title>inline asp.net tags... sorting them all out (&lt;%$, &lt;%=, &lt;%, &lt;%#, etc.)</title>
      <description>&lt;h2&gt;There are all sorts of different inline tags, and I haven&amp;#39;t found a place that explains them all in one place, so here is the quick and dirty...&lt;/h2&gt;
*UDPATED 2012-02-22: Thanks to Conrad Buck and Austin for updates!
&lt;ul&gt;
  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/k6xeyd4z.aspx"&gt;http://msdn.microsoft.com/en-us/library/k6xeyd4z.aspx&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms178472.aspx"&gt;http://msdn.microsoft.com/en-us/library/ms178472.aspx&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
    &lt;h1 style="text-align: center"&gt;
        &amp;lt;% ... %&amp;gt;&lt;/h1&gt;
    &lt;p&gt;
        The most basic inline tag, basically runs normal code:&amp;nbsp;&lt;/p&gt;
    &lt;pre class="prettyprint"&gt;&amp;lt;% if (User.IsInRole(&amp;quot;admin&amp;quot;)) { %&amp;gt;
    You can see this
&amp;lt;% } else { %&amp;gt;
    You are no admin fool!
&amp;lt;%} %&amp;gt;&lt;/pre&gt;
    &lt;p&gt;
        &lt;a href="http://msdn2.microsoft.com/en-us/library/ms178135%28vs.80%29.aspx" target="_blank"&gt;
            http://msdn2.microsoft.com/en-us/library/ms178135(vs.80).aspx&lt;/a&gt;&lt;/p&gt;
    &lt;p&gt;
        &amp;nbsp;&lt;/p&gt;
    &lt;p&gt;
        &amp;nbsp;&lt;/p&gt;
    &lt;a href="http://msdn2.microsoft.com/en-us/library/ms178135%28vs.80%29.aspx" target="_blank"&gt;
    &lt;/a&gt;
    &lt;h1 style="text-align: center"&gt;
        &amp;lt;%= ... %&amp;gt;&lt;/h1&gt;
    &lt;p&gt;
        Used for small chunks of information, usually from objects and single pieces of
        information like a single string or int variable:&amp;nbsp;&lt;/p&gt;
    &lt;pre class="prettyprint"&gt;The Date is now &amp;lt;%= DateTime.Now.ToShortDateString() %&amp;gt;
The value of string1 is &amp;lt;%= string1 %&amp;gt;&amp;nbsp;&lt;/pre&gt;
    &lt;p&gt;
        &lt;a href="http://msdn2.microsoft.com/en-us/library/6dwsdcf5%28VS.71%29.aspx"&gt;http://msdn2.microsoft.com/en-us/library/6dwsdcf5(VS.71).aspx&lt;/a&gt;&lt;/p&gt;
    &lt;p&gt;
        *note: &amp;lt;%= is the equivalent of Response.Write() -&amp;nbsp; Courtesy of Adam from
        the US,thanks!&lt;/p&gt;
    &lt;p&gt;
        &amp;nbsp;&lt;/p&gt;
    &lt;p&gt;
        &amp;nbsp;&lt;/p&gt;
    &lt;a href="http://msdn2.microsoft.com/en-us/library/6dwsdcf5%28VS.71%29.aspx"&gt;&lt;/a&gt;
    &lt;h1 style="text-align: center"&gt;
        &amp;lt;%# .. %&amp;gt;&lt;/h1&gt;
    &lt;p&gt;
        Used for Binding Expressions; such as Eval and Bind, most often found in data controls
        like GridView, Repeater, etc.:&lt;/p&gt;
    &lt;pre class="prettyprint"&gt;&amp;lt;asp:Repeater ID=&amp;quot;rptMeetings&amp;quot; DataSourceID=&amp;quot;meetings&amp;quot; 
    runat=&amp;quot;server&amp;quot;&amp;gt;
    &amp;lt;ItemTemplate&amp;gt;
        &amp;lt;%# Eval(&amp;quot;MeetingName&amp;quot;)%&amp;gt;
    &amp;lt;/ItemTemplate&amp;gt;
&amp;lt;/asp:Repeater&amp;gt;&lt;/pre&gt;
    &lt;p&gt;
        &lt;a href="http://msdn2.microsoft.com/en-us/library/ms178366.aspx" target="_blank"&gt;http://msdn2.microsoft.com/en-us/library/ms178366.aspx&lt;/a&gt;&lt;/p&gt;
    &lt;p&gt;
        &amp;nbsp;&lt;/p&gt;
    &lt;p&gt;
        &amp;nbsp;&lt;/p&gt;
    &lt;a href="http://msdn2.microsoft.com/en-us/library/ms178366.aspx" target="_blank"&gt;
    &lt;/a&gt;
    &lt;h1 style="text-align: center"&gt;
        &amp;lt;%$ ... %&amp;gt;&lt;/h1&gt;
    &lt;p&gt;
        Used for expressions, not code; often seen with DataSources:&amp;nbsp;&lt;/p&gt;
    &lt;pre class="prettyprint"&gt;&amp;lt;asp:SqlDataSource ID=&amp;quot;party&amp;quot; runat=&amp;quot;server&amp;quot; 
    ConnectionString=&amp;quot;&amp;lt;%$ ConnectionStrings:letsParty %&amp;gt;&amp;quot; 
    SelectCommand=&amp;quot;SELECT * FROM [table]&amp;quot;
/&amp;gt;&lt;/pre&gt;
    &lt;p&gt;
        &lt;a href="http://msdn2.microsoft.com/en-us/library/d5bd1tad.aspx" target="_blank"&gt;http://msdn2.microsoft.com/en-us/library/d5bd1tad.aspx&lt;/a&gt;&lt;/p&gt;
    &lt;p&gt;
        &amp;nbsp;&lt;/p&gt;
    &lt;p&gt;
        &amp;nbsp;&lt;/p&gt;
    &lt;a href="http://msdn2.microsoft.com/en-us/library/d5bd1tad.aspx" target="_blank"&gt;
    &lt;/a&gt;
    &lt;h1 style="text-align: center"&gt;
        &amp;lt;%@ ... %&amp;gt;&lt;/h1&gt;
    &lt;p&gt;
        This is for directive syntax; basically the stuff you see at the top your your aspx
        pages like control registration and page declaration:&amp;nbsp;&lt;/p&gt;
    &lt;pre class="prettyprint"&gt;&amp;lt;%@ Page Language=&amp;quot;C#&amp;quot; 
    MasterPageFile=&amp;quot;~/MasterPage.master&amp;quot; 
    AutoEventWireup=&amp;quot;true&amp;quot; CodeFile=&amp;quot;Default.aspx.cs&amp;quot; 
    Inherits=&amp;quot;_Default&amp;quot; Title=&amp;quot;Untitled Page&amp;quot; %&amp;gt;
&amp;lt;%@ Register TagPrefix=&amp;quot;wp&amp;quot; Namespace=&amp;quot;CustomWebParts&amp;quot; %&amp;gt;&lt;/pre&gt;
    &lt;p&gt;
        &lt;a href="http://msdn2.microsoft.com/en-us/library/xz702w3e%28VS.80%29.aspx" target="_blank"&gt;
            http://msdn2.microsoft.com/en-us/library/xz702w3e(VS.80).aspx&lt;/a&gt;&lt;/p&gt;
    &lt;p&gt;
        &amp;nbsp;&lt;/p&gt;
    &lt;p&gt;
        &amp;nbsp;&lt;/p&gt;
    &lt;a href="http://msdn2.microsoft.com/en-us/library/xz702w3e%28VS.80%29.aspx" target="_blank"&gt;
    &lt;/a&gt;
    &lt;h1 style="text-align: center"&gt;
        &amp;lt;%-- ... --%&amp;gt;&lt;/h1&gt;
    &lt;p&gt;
        This is a server side comment, stuff you don&amp;#39;t want anyone without code access
        to see:&lt;/p&gt;
    &lt;pre class="prettyprint"&gt;&amp;lt;asp:Label ID=&amp;quot;lblAwesome&amp;quot; runat=&amp;quot;server&amp;quot;/&amp;gt;
&amp;lt;%-- sometimes end users make me angry --%&amp;gt;&lt;br /&gt;
&amp;lt;asp:LinkButton ID=&amp;quot;lbEdit&amp;quot; Text=&amp;quot;Edit&amp;quot;
    OnClick=&amp;quot;Edit_Click&amp;quot; runat=&amp;quot;server&amp;quot; /&amp;gt;&lt;/pre&gt;
    &lt;p&gt;
        &lt;a href="http://msdn2.microsoft.com/en-us/library/4acf8afk.aspx" target="_blank"&gt;http://msdn2.microsoft.com/en-us/library/4acf8afk.aspx&lt;/a&gt;&lt;/p&gt;
    &lt;p&gt;
        &amp;nbsp;&lt;/p&gt;
    &lt;p&gt;
    &lt;h1 style="text-align: center"&gt;
        &amp;lt;%: ... %&amp;gt;&lt;/h1&gt;
    &lt;p&gt;
        This tag is identical to the "&amp;lt;%= 
        ... %&amp;gt;" tag except that it auto-html-encodes the value within the tag.  As Phil Haack said: &lt;q&gt;I often tell people it’s &amp;lt;%= but with the = seen from the front.&lt;/q&gt;:&lt;/p&gt;&lt;br /&gt;
    &lt;pre class="prettyprint"&gt;&amp;lt;%: Html.TextBox("FirstName") %&amp;gt;&lt;/pre&gt;
    &lt;p&gt;
        &lt;a href="http://haacked.com/archive/2009/09/25/html-encoding-code-nuggets.aspx" target="_blank"&gt;http://haacked.com/archive/2009/09/25/html-encoding-code-nuggets.aspx&lt;/a&gt;&lt;/p&gt;
    &lt;p&gt;
        &amp;nbsp;&lt;/p&gt;
    &lt;p&gt;
        And that&amp;#39;s that.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
    &lt;a style="float: right; border-width: 0pt" href="http://www.dotnetkicks.com/kick/?url=http%3a%2f%2fnaspinski.net%2fpost%2finline-aspnet-tags-sorting-them-all-out-(3c25242c-3c253d2c-3c252c-3c252c-etc).aspx"&gt;
        &lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http%3a%2f%2fnaspinski.net%2fpost%2finline-aspnet-tags-sorting-them-all-out-(3c25242c-3c253d2c-3c252c-3c252c-etc).aspx&amp;amp;border=003366&amp;amp;bgcolor=003366&amp;amp;cfgcolor=003366&amp;amp;cbgcolor=FFFFFF"
            border="0" alt="kick it on DotNetKicks.com" /&gt;&lt;/a&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=eAP3W29Q0pU:fBzTeKVFzkY:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=eAP3W29Q0pU:fBzTeKVFzkY:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=eAP3W29Q0pU:fBzTeKVFzkY:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=eAP3W29Q0pU:fBzTeKVFzkY:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=eAP3W29Q0pU:fBzTeKVFzkY:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/eAP3W29Q0pU" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/eAP3W29Q0pU/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/inline-aspnet-tags-sorting-them-all-out-(3c25242c-3c253d2c-3c252c-3c252c-etc).aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=0071dd4b-1c58-41bd-8f00-eb735a70ef9f</guid>
      <pubDate>Wed, 22 Feb 2012 09:55:00 -0400</pubDate>
      <category>asp.net</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=0071dd4b-1c58-41bd-8f00-eb735a70ef9f</pingback:target>
      <slash:comments>15</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=0071dd4b-1c58-41bd-8f00-eb735a70ef9f</trackback:ping>
      <wfw:comment>http://naspinski.net/post/inline-aspnet-tags-sorting-them-all-out-(3c25242c-3c253d2c-3c252c-3c252c-etc).aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=0071dd4b-1c58-41bd-8f00-eb735a70ef9f</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=0071dd4b-1c58-41bd-8f00-eb735a70ef9f</feedburner:origLink></item>
    <item>
      <title>Helper Methods for Validating Generated Linq-to-Entities edmx Files using Partial Classes</title>
      <description>&lt;h2&gt;Centralized client and server side validation as well as property and method additions to auto-generated classes&lt;/h2&gt;Say I have an auto-generated &lt;strong&gt;Widget&lt;/strong&gt; class (from a database, generated into a .edmx file):
&lt;pre class="prettyprint"&gt;namespace My.NameSpace
{
    public partial class Widget
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
}&lt;/pre&gt;
&lt;br /&gt;
Now I want to add some methods and validation to the class, but I do not want to edit the class directly.  What I need to do is make a partial class and add the things in there.  This accomplished two things: 1. separates logic from structure and 2. separates the files so another auto-generation or update will not lose the work you do.  This is very simple to do, here is an example:
&lt;pre class="prettyprint"&gt;// be SURE that it is in the same namespace
namespace My.NameSpace
{
    //System.ComponentModel.DataAnnotations
    [MetadataType(typeof(VWidget))]
    public partial class Widget
    {
        // I want to add another property
        public string FullName
        { get { return Name + Id; } }
    }

    // this is the validation segment
    // this is the same as the class name above
    public class VWidget
    {
        [Display(Name = "Widget Name")]
        [Required]
        [StringLength(50)]
        public string Name { get; set; }
    }
}&lt;/pre&gt;
&lt;br /&gt;
Now this was very simple, but it shows how to add this in.  First of all, there is a new property to &lt;strong&gt;Widget&lt;/strong&gt; called 'FullName' which will combine the 'Name' and 'Id' properties.  Not really all that useful, but you can see how it is used.
&lt;br /&gt;&lt;br /&gt;
The next part is really cool, you can put all of your validation in the 'VWidget' class (name doesn't really matter here).  Here you can see that 'Name' is now required, has a max length of 50 characters, and a label will display "Widget Name" instead of the default property name.  This way, if you are using this library with MVC, you can do something this simple:
&lt;pre class="prettyprint"&gt;@using (Html.BeginForm())
{ 
    @Html.ValidationSummary()
    @Html.LabelFor(x =&gt; x.Name)
    @Html.EditorFor(x =&gt; x.Name)
}&lt;/pre&gt;
&lt;br /&gt;
And you will be pushing client-side validation as well as a centralized area to hold your custom labels.  On top of that, in your code, if you simply include:
&lt;pre class="prettyprint"&gt;if (ModelState.IsValid)&lt;/pre&gt;&lt;br /&gt;
You will be enforcing server-side validation as well.&lt;br /&gt;&lt;br /&gt;Later I will get into how you can use .resx files for localization and centralization along with these partial classes.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=uCJe7duGfkU:KKBFS7pLIbs:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=uCJe7duGfkU:KKBFS7pLIbs:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=uCJe7duGfkU:KKBFS7pLIbs:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=uCJe7duGfkU:KKBFS7pLIbs:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=uCJe7duGfkU:KKBFS7pLIbs:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/uCJe7duGfkU" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/uCJe7duGfkU/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/Helper-Methods-for-Validating-Generated-Linq-to-Entities-edmx-Files-using-Partial-Classes.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=a406ea12-987c-46df-971e-5721bd2251e3</guid>
      <pubDate>Tue, 07 Feb 2012 00:48:00 -0400</pubDate>
      <category>c#</category>
      <category>steal some code</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=a406ea12-987c-46df-971e-5721bd2251e3</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=a406ea12-987c-46df-971e-5721bd2251e3</trackback:ping>
      <wfw:comment>http://naspinski.net/post/Helper-Methods-for-Validating-Generated-Linq-to-Entities-edmx-Files-using-Partial-Classes.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=a406ea12-987c-46df-971e-5721bd2251e3</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=a406ea12-987c-46df-971e-5721bd2251e3</feedburner:origLink></item>
    <item>
      <title>Ternary Operator in SQL</title>
      <description>&lt;h2&gt;there technically isn't one, but an equivalent isn't too hard to do&lt;/h2&gt;

This ternary in C#:
&lt;pre class="prettyprint"&gt;(str.Length &gt; 0 ? "yes" : "no");&lt;/pre&gt;
&lt;br /&gt;

Is equivalent to this in SQL:
&lt;pre class="prettyprint"&gt;(CASE WHEN LEN(@str) &gt; 0 THEN "yes" ELSE "no" END);&lt;/pre&gt;
&lt;br /&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=q1N9ecltmi8:6NXk0G9y35s:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=q1N9ecltmi8:6NXk0G9y35s:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=q1N9ecltmi8:6NXk0G9y35s:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=q1N9ecltmi8:6NXk0G9y35s:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=q1N9ecltmi8:6NXk0G9y35s:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/q1N9ecltmi8" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/q1N9ecltmi8/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/Ternary-Operator-in-SQL.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=1be7efe3-cf91-4bc0-afe4-707419bcf61b</guid>
      <pubDate>Fri, 03 Feb 2012 13:32:00 -0400</pubDate>
      <category>sql</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=1be7efe3-cf91-4bc0-afe4-707419bcf61b</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=1be7efe3-cf91-4bc0-afe4-707419bcf61b</trackback:ping>
      <wfw:comment>http://naspinski.net/post/Ternary-Operator-in-SQL.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=1be7efe3-cf91-4bc0-afe4-707419bcf61b</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=1be7efe3-cf91-4bc0-afe4-707419bcf61b</feedburner:origLink></item>
    <item>
      <title>Using a Custom Controller Class in Asp.Net MVC to Simplify Coding</title>
      <description>&lt;h2&gt;Controllers often have some repetitive code, implementing your own Controller class can help eliminate a lot of this&lt;/h2&gt;

Here is a small snippet and how I use some simple tricks to help clean up my Controllers in Asp.Net MVC (using MVC 4 at the moment):

&lt;pre class="prettyprint"&gt;public class MyController : Controller
{
    public MyEntities Db { get; set; }

    protected override void OnActionExecuting(
        ActionExecutingContext filterContext)
    {
        if (filterContext.IsChildAction)
            return;
        this.Db = new MyEntities();
        base.OnActionExecuting(filterContext);
    }

    [HttpPost]
    public ActionResult Index(FormCollection form)
    {
        string srch = form["Search"] ?? string.Empty;
        return RedirectToAction("Index", 
            new { search = srch });
    }

    protected void AttachToDb(EntityObject obj, 
        bool save = false, string entityKeyField = "Id")
    {
            obj.EntityKey = new EntityKey(
                obj.ToPluralizedString(), entityKeyField, 
                obj.GetType().GetProperty("Id")
                .GetValue(obj, null));
            Db.Attach(obj);
            Db.ObjectStateManager.ChangeObjectState(
                obj, System.Data.EntityState.Modified);
            if (save) Db.SaveChanges();
    }
}&lt;/pre&gt;
&lt;br /&gt;
The first thing in the code is simple declaration of an EntityContext - this is implemented directly, but could (and usually should) be implemented differently for dependency injection, but you get the idea.  Here is where I also like to include stuff that is often used and could be vital (and centralized) for an application like an output type for web services (JSON, XML, etc.).
&lt;br /&gt;&lt;br /&gt;  
Next the &lt;span style="font-weight:bold"&gt;OnActionExecuting&lt;/span&gt; is over-ridden and the Context is initialized.  Here is where you can initialize the properties you set above.
&lt;br /&gt;&lt;br /&gt;
The next method, the &lt;span style="font-weight:bold"&gt;HttpPost Index&lt;/span&gt; method is just an example of how often times you can consolidate a commonly used method.  For this example, it was from an application that had searches on all index pages.  Instead of repeating this code in every controller, you can just put it here.
&lt;br /&gt;&lt;br /&gt;
The final method has become very useful.  A use I often find, is when taking in a large model after an Asp.Net MVC POST event, I can attach the model to the Db generically without any extra work&lt;br /&gt;
&lt;br /&gt;
This method is a bit confusing, but it is simply attaching the new model to the Db without a Db lookup.  In my tables, I generally have a field 'Id' that houses the Primary Key of every table, whether it is an Int or Guid.  This way, I can simply pass in whatever object I am currently working with, and by using the &lt;a href="http://naspinski.net/post/Pluralize.aspx"&gt;pluralize&lt;/a&gt; method, and reflection, the method can figure out which table to attach the model to - eliminating the need for me to do extra coding.  Alternatively, if I want to change the Key from 'Id', I can pass that in as well.
&lt;br /&gt;&lt;br /&gt;
Now when I get a model being POSTed, it is easy to deal with:
&lt;pre class="prettyprint"&gt;[HttpPost]
public ActionResult Edit(Widget model)
{
    if(ModelState.IsValid)
    {
        AttachToDb(model, true);
        //do stuff
    }
    else { /*do other stuff*/ }
}&lt;/pre&gt;
&lt;br /&gt;
This avoids the need to take another trip to the DB, change the properties on the object, then submit - streamlining the process very much and cutting down a lot of code.
&lt;br /&gt;&lt;br /&gt;
This would be an example of how this would be done manually with the normal Controller class:

&lt;pre class="prettyprint"&gt;[HttpPost]
public ActionResult Edit(Widget model)
{
    if(ModelState.IsValid)
    {
        MyEntities db = new MyEntities();
        Widget w = db.Widgets.Single(x =&gt; x.Id == model.Id);
        w.Name = model.Name;
        w.Serial = model.Serial;
        db.SaveChanges();
        //do stuff
    }
    else { /*do other stuff*/ }
}&lt;/pre&gt;
&lt;br /&gt;
Not a huge difference when you are just getting 2 values, but you could see how a model with 20 or 30 fields can be cut down from 30+ lines to just 1 or 2.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=x0Ppx4GneJk:d2hfwGa0r-c:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=x0Ppx4GneJk:d2hfwGa0r-c:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=x0Ppx4GneJk:d2hfwGa0r-c:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=x0Ppx4GneJk:d2hfwGa0r-c:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=x0Ppx4GneJk:d2hfwGa0r-c:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/x0Ppx4GneJk" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/x0Ppx4GneJk/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/Using-a-Custom-Controller-Class-in-AspNet-MVC-to-Simplify-Coding.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=0683e027-19b8-44ba-9335-a238370f29f0</guid>
      <pubDate>Thu, 15 Dec 2011 13:23:00 -0400</pubDate>
      <category>asp.net</category>
      <category>c#</category>
      <category>mvc</category>
      <category>steal some code</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=0683e027-19b8-44ba-9335-a238370f29f0</pingback:target>
      <slash:comments>2</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=0683e027-19b8-44ba-9335-a238370f29f0</trackback:ping>
      <wfw:comment>http://naspinski.net/post/Using-a-Custom-Controller-Class-in-AspNet-MVC-to-Simplify-Coding.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=0683e027-19b8-44ba-9335-a238370f29f0</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=0683e027-19b8-44ba-9335-a238370f29f0</feedburner:origLink></item>
    <item>
      <title>Pluralize a String or Class Name in C# and .Net</title>
      <description>&lt;h2&gt;Sometimes you need to pluralize names like when you are working with Entity Framework or countless other sitautaions&lt;/h2&gt;

When you auto-generate from tables in Entity Framework, it will make the table names plural, and the objects singular.  Often times, when you are trying to use more generic functions like creating EntityKey objects for attaching to an unknown table, you will need to pluralize a class name, so for this, I came up with a couple static methods to simply return a plural version of an Object's name or a string itself:

&lt;pre class="prettyprint"&gt;using System.Data.Entity.Design.PluralizationServices;
using System.Globalization;

public static string Pluralize(this string s)
{
    PluralizationService plural = 
        PluralizationService.CreateService(
            CultureInfo.GetCultureInfo("en-us"));
    return plural.Pluralize(s);
}&lt;/pre&gt;
&lt;br /&gt;

Simple enough, now I make this specifically to get the table name of an EntityObject:
&lt;pre class="prettyprint"&gt;public static string GetTableName(this EntityObject obj)
{
    return obj.GetType().Name.Pluralize();
}&lt;/pre&gt;

&lt;br /&gt;
In use:
&lt;pre class="prettyprint"&gt;//returns "Cats":
string cats = "Cat".Pluralize();

//now specifically for EntityObjects:
string tableName = MyEntityObject.GetTableName();&lt;/pre&gt;&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=4V9tUCgBdnw:zK1LlzBHUJU:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=4V9tUCgBdnw:zK1LlzBHUJU:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=4V9tUCgBdnw:zK1LlzBHUJU:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=4V9tUCgBdnw:zK1LlzBHUJU:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=4V9tUCgBdnw:zK1LlzBHUJU:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/4V9tUCgBdnw" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/4V9tUCgBdnw/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/Pluralize.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=4dab230a-b778-4cee-8b6b-d83c3b46c25e</guid>
      <pubDate>Thu, 08 Dec 2011 22:13:00 -0400</pubDate>
      <category>c#</category>
      <category>entities</category>
      <category>linq-to-sql</category>
      <category>mvc</category>
      <category>steal some code</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=4dab230a-b778-4cee-8b6b-d83c3b46c25e</pingback:target>
      <slash:comments>2</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=4dab230a-b778-4cee-8b6b-d83c3b46c25e</trackback:ping>
      <wfw:comment>http://naspinski.net/post/Pluralize.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=4dab230a-b778-4cee-8b6b-d83c3b46c25e</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=4dab230a-b778-4cee-8b6b-d83c3b46c25e</feedburner:origLink></item>
    <item>
      <title>My Case For Using Both UNIQUEIDENTIFIER (Guid) -and- INT Ids in every database table</title>
      <description>&lt;h2&gt;Case for dual database accessors (not keys) - Guid vs Int/UniqueIdentifier vs Int&lt;/h2&gt;
Let's face it, you never know what exactly is going to end up with your next application.  Has an application ever ended up exactly where it was planned in the beginning?  I would say never.
&lt;br /&gt;&lt;br /&gt;
There is an &lt;a href="http://www.google.com/search?gcx=c&amp;sourceid=chrome&amp;ie=UTF-8&amp;q=primary+key+guid+vs+int"&gt;insane amount of writing on the debate of int vs guid&lt;/a&gt;, both have their pros and cons, both have storage, index and coding implications and we know (or can find) almost all of them with a simple search.  Yet there is no consensus on which is the best, I am not here to add to that discussion. 
&lt;br /&gt;&lt;br /&gt;
Therefore I propose using BOTH - hear me out.
&lt;br /&gt;&lt;br /&gt;
I propose that the best solution is to provide ONE of the two as your primary key, I prefer Guid as the PK, as it can be referenced more universally (think recycle bin, etc.), but it does have the added indexing cost of being larger; then simply add the auto-incrementing integer as an additional field.  Whichever one you choose as your alternative (integer in my case) is simply as a just-in-case means of accessing your data - also indexed.  This provides you the best of both worlds, without too much sacrifice.  For example, you get the ubiquity of being able to generate a Guid anywhere (without a DB trip), but also have the ability to access your data by a clean 4-bit integer.  If for some reason, the code is accessed by software that relies on integers, you are not stuck without one, and vice-versa.
&lt;br /&gt;&lt;br /&gt;
Yes, this will obviously cause more data to be stored for every entry in a table (I am talking about main tables here, not necessarily lookup tables, etc.).  This will cause extra index storage as well, but in the long run, I feel it provides enough advantage and future-proofing to justify the sacrifice.  Now tell me how wrong I am...&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=-FoeXs1zVQk:CQgbNLP2ijw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=-FoeXs1zVQk:CQgbNLP2ijw:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=-FoeXs1zVQk:CQgbNLP2ijw:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=-FoeXs1zVQk:CQgbNLP2ijw:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=-FoeXs1zVQk:CQgbNLP2ijw:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/-FoeXs1zVQk" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/-FoeXs1zVQk/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/My-Case-For-Using-Both-UNIQUEIDENTIFIER--and--INT-Ids-in-every-database-table.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=6874e26b-f463-431f-a290-f299f4e6c5fe</guid>
      <pubDate>Mon, 07 Nov 2011 17:39:00 -0400</pubDate>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=6874e26b-f463-431f-a290-f299f4e6c5fe</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=6874e26b-f463-431f-a290-f299f4e6c5fe</trackback:ping>
      <wfw:comment>http://naspinski.net/post/My-Case-For-Using-Both-UNIQUEIDENTIFIER--and--INT-Ids-in-every-database-table.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=6874e26b-f463-431f-a290-f299f4e6c5fe</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=6874e26b-f463-431f-a290-f299f4e6c5fe</feedburner:origLink></item>
    <item>
      <title>Constraining Routes in MVC to an Enum the Easy Way</title>
      <description>&lt;h2&gt;simple way to constrain a route to only allow enum values&lt;/h2&gt;
Say I have the following enum:
&lt;pre class="prettyprint"&gt;public enum SearchType { Facilities, Courses, Exercises};&lt;/pre&gt;
&lt;br /&gt;
And I only want those the be available in route &lt;string&gt;Search/{SearchType}&lt;/strong&gt;.  I could constrain it manually with a string, but then what if the enum changes and I have this in a bunch of routes?  Here is a simple way to accomplish this constraint:
&lt;pre class="prettyprint"&gt;public static void RegisterRoutes(RouteCollection routes)
{
    List&lt;string&gt; searchTypeL = new List&lt;string&gt;();
    foreach (Enums.SearchType type in 
        Enum.GetValues(typeof(Enums.SearchType))) 
    { searchTypeL.Add(type.ToString()); }
    string searchTypes = string.Join("|", searchTypeL);
    
    routes.MapRoute(
        "Searches",
        "Search/{type}",
        new { controller = "Search", action = "Index" },
        new { type = searchTypes }
    )
    ...
&lt;/pre&gt;
&lt;br /&gt;
Very basic, all this does is enumerate through your enum and create a simple string to filter with.&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=9bLx8kKdke4:2AxOyw6ncRQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=9bLx8kKdke4:2AxOyw6ncRQ:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=9bLx8kKdke4:2AxOyw6ncRQ:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=9bLx8kKdke4:2AxOyw6ncRQ:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=9bLx8kKdke4:2AxOyw6ncRQ:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/9bLx8kKdke4" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/9bLx8kKdke4/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/Constraining-Routes-in-MVC-to-an-Enum-the-Easy-Way.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=0271b592-bab0-45a9-95f6-85d2fd19ca2d</guid>
      <pubDate>Thu, 06 Oct 2011 17:40:00 -0400</pubDate>
      <category>asp.net</category>
      <category>c#</category>
      <category>mvc</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=0271b592-bab0-45a9-95f6-85d2fd19ca2d</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=0271b592-bab0-45a9-95f6-85d2fd19ca2d</trackback:ping>
      <wfw:comment>http://naspinski.net/post/Constraining-Routes-in-MVC-to-an-Enum-the-Easy-Way.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=0271b592-bab0-45a9-95f6-85d2fd19ca2d</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=0271b592-bab0-45a9-95f6-85d2fd19ca2d</feedburner:origLink></item>
    <item>
      <title>Monitoring a DOM Element for Modification with jQuery</title>
      <description>&lt;h2&gt;'watching' an element for any change within it&lt;/h2&gt;
I recently ran into a situation where I had to modify a site that relied on an incredibly obfuscated and impossible to understand javascript file.  I had to add in some elements after everything was populated with some function I didn't get, so I had to wait until a specific element was populated to do anything.  Turns out the &lt;strong&gt;DOMNodeInserted&lt;/strong&gt; event is what I needed:
&lt;pre class="prettyprint"&gt;var title = $("b.facility");
var title = $('#title');//the element I want to monitor
title.bind('DOMNodeInserted', function(e) {
    alert('element now contains: ' + $(e.target).html());
});&lt;/pre&gt;
&lt;br /&gt;
Pretty simple, but took me forever to figure out...&lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=CaJHGcA9iyc:Z-IAtEtLTnI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=CaJHGcA9iyc:Z-IAtEtLTnI:gIN9vFwOqvQ"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=CaJHGcA9iyc:Z-IAtEtLTnI:gIN9vFwOqvQ" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/naspinski?a=CaJHGcA9iyc:Z-IAtEtLTnI:F7zBnMyn0Lo"&gt;&lt;img src="http://feeds.feedburner.com/~ff/naspinski?i=CaJHGcA9iyc:Z-IAtEtLTnI:F7zBnMyn0Lo" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/naspinski/~4/CaJHGcA9iyc" height="1" width="1"/&gt;</description>
      <link>http://feedproxy.google.com/~r/naspinski/~3/CaJHGcA9iyc/post.aspx</link>
      <author>naspinski</author>
      <comments>http://naspinski.net/post/Monitoring-a-DOM-Element-for-Modification-with-jQuery.aspx#comment</comments>
      <guid isPermaLink="false">http://naspinski.net/post.aspx?id=eeb1306b-b316-480c-975d-da2851f07c2c</guid>
      <pubDate>Thu, 29 Sep 2011 16:47:00 -0400</pubDate>
      <category>javascript</category>
      <category>jquery</category>
      <category>steal some code</category>
      <dc:publisher>naspinski</dc:publisher>
      <pingback:server>http://naspinski.net/pingback.axd</pingback:server>
      <pingback:target>http://naspinski.net/post.aspx?id=eeb1306b-b316-480c-975d-da2851f07c2c</pingback:target>
      <slash:comments>1</slash:comments>
      <trackback:ping>http://naspinski.net/trackback.axd?id=eeb1306b-b316-480c-975d-da2851f07c2c</trackback:ping>
      <wfw:comment>http://naspinski.net/post/Monitoring-a-DOM-Element-for-Modification-with-jQuery.aspx#comment</wfw:comment>
      <wfw:commentRss>http://naspinski.net/syndication.axd?post=eeb1306b-b316-480c-975d-da2851f07c2c</wfw:commentRss>
    <feedburner:origLink>http://naspinski.net/post.aspx?id=eeb1306b-b316-480c-975d-da2851f07c2c</feedburner:origLink></item>
  </channel>
</rss>
