<?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>David Muto</title>
	<atom:link href="http://davidmuto.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://davidmuto.com</link>
	<description>Just another WordPress Blog!</description>
	<lastBuildDate>Tue, 10 Jan 2012 18:46:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='davidmuto.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>David Muto</title>
		<link>http://davidmuto.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://davidmuto.com/osd.xml" title="David Muto" />
	<atom:link rel='hub' href='http://davidmuto.com/?pushpress=hub'/>
		<item>
		<title>Set up a Subversion Server in EC2</title>
		<link>http://davidmuto.com/2011/12/24/set-up-a-subversion-server-in-ec2/</link>
		<comments>http://davidmuto.com/2011/12/24/set-up-a-subversion-server-in-ec2/#comments</comments>
		<pubDate>Sat, 24 Dec 2011 20:21:47 +0000</pubDate>
		<dc:creator>David Muto</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Subversion]]></category>
		<category><![CDATA[SVN]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://davidmuto.com/?p=54</guid>
		<description><![CDATA[I recently wanted to setup a subversion server. Initially I thought of using Beanstalk since they handle pretty much everything for you for a very small monthly fee. However, I thought I might set up my own server in order &#8230; <a href="http://davidmuto.com/2011/12/24/set-up-a-subversion-server-in-ec2/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidmuto.com&amp;blog=19878726&amp;post=54&amp;subd=davidmuto&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I recently wanted to setup a subversion server. Initially I thought of using Beanstalk since they handle pretty much everything for you for a very small monthly fee. However, I thought I might set up my own server in order to learn the process.</p>
<p>I found a few online resources that outlined the process, but none of them were exactly what I needed, so I decided to write this post to go over the steps in detail. Hopefully this helps!</p>
<p>The steps we are going to take:</p>
<ul>
<li>Create a KeyPair, Security Group and Elastic IP in AWS</li>
<li>Create a new Micro instance (64-bit Linux) in AWS</li>
<li>Connect to the new instance using SSH</li>
<li>Install a few tools on our new instance</li>
<li>Create directories for repositories and auth settings</li>
<li>Configure apache for servicing SVN requests</li>
<li>Try it out</li>
</ul>
<h2>Getting Set Up in AWS</h2>
<p>The first step is to login to the AWS Management Console.</p>
<ol>
<li>On the left side of the screen under Network and Security, select KeyPairs.</li>
<li>Create a new Key Pair called SVN &#8211; this will create the key pair and initiate a download. Store this key in a safe place &#8211; i.e. do not lose it!</li>
</ol>
<p>Next, click on Security Groups (under Network and Security)</p>
<ol>
<li>Click Create Security Group</li>
<li>Call it Web (Linux) and set the description to Subversion and HTTP</li>
<li>Once it&#8217;s been created, select the new group and click the Inbound tab (bottom of the screen)</li>
<li>Add three inbound rules, SSH (22), HTTP (80), HTTPS (443)</li>
<li>Apply your changes</li>
</ol>
<p>Ok, now we have the &#8220;firewall&#8221; rules setup and a KeyPair (used to connect via SSH) to connect to an instance. Now we need to create a new server instance in EC2.</p>
<ol>
<li>On the left menu under Instances, select instances</li>
<li>From the toolbar select Launch Instance</li>
<li>Choose Launch Classic Wizard and click continue</li>
<li>From the QuickStart tab, choose Basic 64-bit Amazon Linux AMI</li>
<li>On the next screen, set the Number of Instances to 1, the Instance Type to &#8220;Micro&#8221; and click Continue</li>
<li>From the Advanced Instance Options screen, leave all the defaults and click continue</li>
<li>Add any tags you want and click continue</li>
<li>On the next screen, select the KeyPair we created earlier and click continue</li>
<li>From the Configure Firewall screen, select the Security Group we created earlier</li>
<li>Click next/continue until the instance is created</li>
</ol>
<p>We now want to connect and Elastic IP to our instance (this must be done every time you start the instance&#8230;Amazon doesn&#8217;t automate this at all).</p>
<ol>
<li>From the left menu under Network and Security, select Elastic IPs</li>
<li>Click Allocate New Address from the toolbar and click Yes when prompted</li>
<li>Right click on the new IP address and select &#8220;associate&#8221; from the menu</li>
<li>Select your new instance from the list</li>
</ol>
<p>The last step would be to create an A record on your DNS server for the new IP. For the purposes of this article I&#8217;m going to assume that you&#8217;ve done this step, however while going through the rest of this post, you can simply replace &lt;domain&gt; with your Elastic IP address supplied by Amazon and get the same results.</p>
<h2>Connecting to Your New Instance</h2>
<p>Now that we&#8217;ve got the server all setup in AWS, we need to connect to our new server and install some applications that will make things a little easier to work with.</p>
<p>There are loads of SSH applications out there that will let you use SSH from Windows (my preference is Putty &#8211; and it&#8217;s free). If you&#8217;re connecting from a Mac or any &#8216;nix system, SSH is already built-in. For this article, I&#8217;ll assume we&#8217;re using a Mac/Nix installation. If you&#8217;re using Windows, <a title="Connecting to EC2 with Putty" href="http://www.powercram.com/2009/07/connecting-to-aws-ec2-instance-linux.html" target="_blank">check out this post</a> on connecting to EC2 with Putty.</p>
<p>Connecting from a Console</p>
<ol>
<li>If you&#8217;re using a Mac, you will need to open a terminal (Applications-&gt;Utilities-&gt;Terminal)</li>
<li>If you&#8217;re using Nix, I assume you know how to open a terminal window <img src='http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
<li>cd to the directory where you saved the KeyPair file (.pem) we created ealier</li>
<li>Change the permissions of this file (to stop SSH from complaining about it): <code>sudo chmod 600 &lt;keypair&gt;</code></li>
<li>Type command: <code>ssh -i &lt;keypair&gt; ec2-user@&lt;domain&gt;</code> where &lt;keypair&gt; is the KeyPair file we created ealier and &lt;domain&gt; is to host you pointed to the Elastic IP (can be an IP address if you like)</li>
<li>The first time you connect, you might get a warning about trusting a certificate&#8230;type or select yes when prompted</li>
</ol>
<h2>You&#8217;re In! Now what?</h2>
<p>Now that we&#8217;re connected to the instance, we need to install a few things. I should note, I&#8217;m a big fan of emacs, so I always install it. If you&#8217;re not familiar with Unix editors, stick to pico to keep things simple. For the remainder of this article, I&#8217;ll use the word editor to refer to your preferred editor of choice on Linux.</p>
<p>Run the following commands to install subversion and svnserve.</p>
<p><pre class="brush: bash;">
sudo yum install mod_dav_svn subversion
</pre></p>
<p>Next we&#8217;re going to create a few new folders:</p>
<p><pre class="brush: bash;">
sudo mkdir -p /data/svn/repos /data/svn/logins /data/svn/scripts
sudo chown -R apache.apache /data/svn
</pre></p>
<p>Now we need to create a subversion account to use for connecting to a repository. To do this we are going to create a new auth file and the create a script to handle adding new users in the future. To do this, run the following commands:</p>
<p><pre class="brush: bash;">
cd /data/svn/logins
sudo htpasswd -cm svn-auth-conf
</pre></p>
<p>We should now make the login file a little more secure by running <code>sudo chmod 600 svn-auth-conf</code>. Next, we&#8217;re going to create a script called create_user.sh that we can use to add user&#8217;s in the future. This will make sure that we don&#8217;t forget the commands and also ensure that we don&#8217;t accidentally include -c again which will create a new file (overriding anything existing) &#8211; bad.</p>
<p>Using your editor, create the following script (in /data/svn/scripts), save it to a file called create_user.sh and then run sudo chmod +x create_user.sh to add execute rights to the file.</p>
<p><pre class="brush: bash;">
#!/bin/bash
user_name=&quot;$1&quot;
auth_file=&quot;../logins/svn-auth-conf&quot;

if [ &quot;$user_name&quot; = &quot;&quot; ]; then
    echo -n &quot;Enter user name: &quot;
    read user_name
fi

chmod 700 $auth_file
if [ $? -eq 0 ]; then
    htpasswd -m $auth_file $user_name
    chmod 600 $auth_file
fi

</pre></p>
<p>We can use this script by passing in a username or allowing the script to prompt us for one:</p>
<p><pre class="brush: bash;">
sudo ./create_user.sh davidmuto
#or
sudo ./create_user.sh
</pre></p>
<p>Now we need a script that allows us to create repositories. The reason we make this a script is to save us from retyping the same commands every time we create a repo (very prone to error). Here&#8217;s a script that will create a repository and set all of the necessary permissions on the files for being served by apache.</p>
<p><pre class="brush: bash;">
#!/bin/bash
repo_name=&quot;$1&quot;
path_to_repo=&quot;&quot;

if [ &quot;$repo_name&quot; = &quot;&quot; ]; then
    echo -n &quot;What should the repo be called?: &quot;
    read repo_name
fi

path_to_repo=&quot;../repos/$repo_name&quot;
svnadmin create $path_to_repo
if [ $? -eq 0 ]; then
    sudo chown -R apache.apache $path_to_repo
    sudo chcon -R -t httpd_sys_content_t $path_to_repo
    echo &quot;Successfully create repo '$path_to_repo'&quot;
else
    echo &quot;Could not create repository $path_to_repo&quot;
fi
</pre></p>
<h2>The Final Step!</h2>
<p>Our last step it to set up the apache config file for servicing subversion repo requests.</p>
<ol>
<li>Navigate to /etc/httpd/conf.g</li>
<li>Using your editor open the subversion.conf file for editing (much be run using sudo, e.g. sudo emacs subversion.conf or sudo vi subversino.conf)</li>
<li>Add the following Location element to the file<br />
<pre class="brush: bash;">
&lt;Location /&gt;
  DAV svn
  SVNParentPath /data/svn/repos
  AuthType Basic
  AuthName &quot;My Subversion Realm&quot;
  AuthUserFile /data/svn/logins/svn-auth-conf
  Require valid-user
&lt;/Location&gt;
</pre></li>
<li>Restart the apache service: sudo service httpd restart</li>
</ol>
<h2>Testing it Out</h2>
<p>Now let&#8217;s run through the process of creating a new repo and connecting to it.</p>
<ol>
<li>Navigate to /data/svn/scripts</li>
<li>Create a user (if needed): sudo ./create_user.sh [user_name]</li>
<li>Create a new repo: sudo ./create_repo.sh [repo_name]</li>
<li>Using your favourite subversion client, checkout your new repo at http://&lt;domain&gt;/&lt;repo_name&gt;</li>
</ol>
<p>I hope this posts helps someone in need. If you guys notice anything I&#8217;ve missed, please feel free to let me know and I&#8217;ll update this post as needed.</p>
<p><strong>Happy Coding!</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidmuto.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidmuto.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidmuto.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidmuto.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidmuto.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidmuto.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidmuto.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidmuto.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidmuto.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidmuto.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidmuto.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidmuto.wordpress.com/54/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidmuto.wordpress.com/54/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidmuto.wordpress.com/54/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidmuto.com&amp;blog=19878726&amp;post=54&amp;subd=davidmuto&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davidmuto.com/2011/12/24/set-up-a-subversion-server-in-ec2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2cf9c90cc7eb61ee14be216aea33a2be?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">davidmuto</media:title>
		</media:content>
	</item>
		<item>
		<title>NSDate from OData</title>
		<link>http://davidmuto.com/2011/07/29/nsdate-from-odata/</link>
		<comments>http://davidmuto.com/2011/07/29/nsdate-from-odata/#comments</comments>
		<pubDate>Fri, 29 Jul 2011 22:42:48 +0000</pubDate>
		<dc:creator>David Muto</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[OData]]></category>

		<guid isPermaLink="false">http://davidmuto.wordpress.com/?p=40</guid>
		<description><![CDATA[Recently I&#8217;ve been working on an iOS project that loads data that we publish via the Open Data Protocol (OData). At first everything was working perfectly. I was using JSONKit and NSOperation to download and process the information. That was &#8230; <a href="http://davidmuto.com/2011/07/29/nsdate-from-odata/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidmuto.com&amp;blog=19878726&amp;post=40&amp;subd=davidmuto&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently I&#8217;ve been working on an iOS project that loads data that we publish via the Open Data Protocol (<a href="http://www.odata.org/" target="_blank">OData</a>).</p>
<p>At first everything was working perfectly. I was using <a href="https://github.com/johnezang/JSONKit" target="_blank">JSONKit</a> and <a href="http://developer.apple.com/library/ios/#documentation/cocoa/reference/NSOperation_class/Reference/Reference.html" target="_blank">NSOperation</a> to download and process the information. That was until I had to get a DateTime object&#8230;which resulted in an epic fail!</p>
<p>It turns out that WCF Data Services publish DateTime objects as a new Date object represented by the time in milliseconds (not seconds) since January 1, 1970. Anyone familiar with <a href="http://en.wikipedia.org/wiki/Epoch_(reference_date)" target="_blank">EPOCH dates</a> knows about January 1, 1970 right?</p>
<p>The problem isn&#8217;t so much in that it publishes dates from a known time, rather that it does it in the least accessible way! The value is rendered out (in JSON) as &#8220;\/Date(1311836400000)\/&#8221; &#8211; yeah..I know, right?</p>
<p>So now I had to figure out a nice way to parse this very custom date format in Objective-C. This led me to the shocking (and borderline unacceptable) realization that objective-c (lower case to drive the point home) has no support for regular expressions. There&#8217;s no punch-line to this joke&#8230;for real. No support for regex. A Unix-based OS has a development language that has no support for something that is natively supported (see the * below)!</p>
<p>To start, I decided to add a category to the NSDate object that would allow me to work with these ridiculous strings.</p>
<p>NSDate+OData.h</p>
<p><pre class="brush: objc;">
#import &lt;Foundation/Foundation.h&gt;

@interface NSDate (OData)

- (id)initWithODataString:(NSString *)dateString;
- (NSString *)toODataQueryFormat;

+ (NSDate *)dateFromString:(NSString *)dateString;

@end
</pre></p>
<p>NSDate+OData.m</p>
<p><pre class="brush: objc;">
#import &quot;NSDate+OData.h&quot;

@implementation NSDate (OData)

- (id)initWithODataString:(NSString *)dateString
{
    return [[NSDate dateFromString:dateString] retain];
}

- (NSString *)toODataQueryFormat
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@&quot;yyyy-MM-dd'T'HH:mm:ss&quot;];

    NSString *formattedDate = [formatter stringFromDate:self];
    [formatter release];

    return formattedDate;
}

+ (NSDate *)dateFromString:(NSString *)dateString
{
    NSInteger startIndex = [dateString rangeOfString:@&quot;(&quot;].location;
    NSInteger endIndex = [dateString rangeOfString:@&quot;)&quot;].location - startIndex;
    long long ticks = [[dateString substringWithRange:NSMakeRange(startIndex + 1, endIndex)] longLongValue];

    NSDate *date = [NSDate dateWithTimeIntervalSince1970:(ticks / 1000)];
    return date;
}

@end
</pre></p>
<p>The code above allows me to get an NSDate from the crazy OData DateTime string and also convert an NSDate to another (quite different) format used by OData to query based on a DateTime value.</p>
<p>To get an NSDate from the OData string, I am substring&#8217;ing the value between the two brackets. This value is then converted to a long long value (twice on purpose for you .NET developers out there). The NSDate has a static method called dateWithTimeIntervalSince1970: that will return an (autoreleased) NSDate object with the value of the time (in seconds) since January 1, 1970.</p>
<p>To get the date to the query format used by OData (see <a href="http://www.odata.org/developers/protocols/uri-conventions" target="_blank">OData URI Conventions</a>), we need to take an NSDate and get it into the format &#8220;yyyy-MM-dd&#8217;T'HH:mm:ss&#8221; for example, &#8220;2011-07-29T18:15:00&#8243;.</p>
<p>I hope this information helps someone, as I was unable to find a simple example online anywhere (although I will concede that my googling skills could use some work).</p>
<p>* Please don&#8217;t take this as a complete knock to Objective-C. The language is quite easy to work with and definitely robust&#8230;just lame on the regex front!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidmuto.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidmuto.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidmuto.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidmuto.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidmuto.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidmuto.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidmuto.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidmuto.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidmuto.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidmuto.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidmuto.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidmuto.wordpress.com/40/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidmuto.wordpress.com/40/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidmuto.wordpress.com/40/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidmuto.com&amp;blog=19878726&amp;post=40&amp;subd=davidmuto&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davidmuto.com/2011/07/29/nsdate-from-odata/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2cf9c90cc7eb61ee14be216aea33a2be?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">davidmuto</media:title>
		</media:content>
	</item>
		<item>
		<title>Showing Enums as a Select List in MVC and Razor</title>
		<link>http://davidmuto.com/2011/07/27/showing-enums-as-a-select-list-in-mvc-and-razor/</link>
		<comments>http://davidmuto.com/2011/07/27/showing-enums-as-a-select-list-in-mvc-and-razor/#comments</comments>
		<pubDate>Wed, 27 Jul 2011 16:03:55 +0000</pubDate>
		<dc:creator>David Muto</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Helper Methods]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Razor]]></category>

		<guid isPermaLink="false">http://davidmuto.wordpress.com/?p=23</guid>
		<description><![CDATA[Recently I needed to show a drop down list of all of the enumeration values. So I did what we all do and hit up Google. While there was plenty of information out there detailing how to convert the enum &#8230; <a href="http://davidmuto.com/2011/07/27/showing-enums-as-a-select-list-in-mvc-and-razor/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidmuto.com&amp;blog=19878726&amp;post=23&amp;subd=davidmuto&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently I needed to show a drop down list of all of the enumeration values. So I did what we all do and hit up Google. While there was plenty of information out there detailing how to convert the enum to a Dictionary&lt;int, string&gt; and render it, I couldn&#8217;t find something that fit my needs.</p>
<p>Essentially I have an enumeration of field types. I wanted to display the names of those fields in a drop down list, but be able to make some of them prettier. Here is the enumeration:</p>
<p><pre class="brush: csharp;">
public enum FieldType
{
    Text = 1,
    HTML = 2,
    [Display(Name = &quot;Date/Time&quot;)]
    DateTime = 3,
    Number = 4,
    [Display(Name = &quot;Dropdown List&quot;)]
    DropdownList = 5
}
</pre></p>
<p>Now I need a way to show the items in a drop down list, and set the selected one (from the Model) to selected. I decided the easiest way would be to use an editor template. So I created the FieldType editor template (under /Views/Shared/EditorTemplates) using the code below:</p>
<p><pre class="brush: csharp;">
@model FieldType
@using System.ComponentModel.DataAnnotations
&lt;select name=&quot;@ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty)&quot;&gt; 
@foreach (var name in Enum.GetNames(typeof(FieldType))) {
    &lt;option selected=&quot;selected&quot; value=&quot;@name&quot;&gt;@DisplayName(name)&lt;/option&gt;
}
&lt;/select&gt;

@helper DisplayName(string name) {
    var attr = typeof(FieldType).GetField(name).GetCustomAttributes(typeof(DisplayAttribute), false).FirstOrDefault() as DisplayAttribute;

    if (attr != null)
    {
        @attr.Name
    }
    else
    {
        @name
    }
}
</pre></p>
<p>Now when I want to render a FieldType property of an object, I can just use the Html.EditorFor extension as I would for any other object:</p>
<p><pre class="brush: xml;">&lt;/pre&gt;
&lt;div class=&quot;editor-label&quot;&gt;@Html.LabelFor(model =&gt; model.Type)&lt;/div&gt;
&lt;div class=&quot;editor-field&quot;&gt;@Html.EditorFor(model =&gt; model.Type)
 @Html.ValidationMessageFor(model =&gt; model.Type)&lt;/div&gt;
&lt;pre&gt;
</pre></p>
<p>And Voila!</p>
<p>If for some reason you cannot name your editor template the same as the type, you can supply the name of the template to the EditorFor method using one of the overloads provided.</p>
<p>Happy coding!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidmuto.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidmuto.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidmuto.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidmuto.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidmuto.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidmuto.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidmuto.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidmuto.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidmuto.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidmuto.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidmuto.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidmuto.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidmuto.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidmuto.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidmuto.com&amp;blog=19878726&amp;post=23&amp;subd=davidmuto&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davidmuto.com/2011/07/27/showing-enums-as-a-select-list-in-mvc-and-razor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2cf9c90cc7eb61ee14be216aea33a2be?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">davidmuto</media:title>
		</media:content>
	</item>
		<item>
		<title>Global Namespace Includes with MVC3 and Razor</title>
		<link>http://davidmuto.com/2011/03/07/global-namespace-includes-with-mvc3-and-razor/</link>
		<comments>http://davidmuto.com/2011/03/07/global-namespace-includes-with-mvc3-and-razor/#comments</comments>
		<pubDate>Mon, 07 Mar 2011 22:10:21 +0000</pubDate>
		<dc:creator>David Muto</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Razor]]></category>

		<guid isPermaLink="false">http://davidmuto.wordpress.com/?p=4</guid>
		<description><![CDATA[While I&#8217;m loving MVC3 and the Razor view engine, I was sorely disappointed when I couldn&#8217;t use the system.web/pages/namespaces collection in web.config to add global namespace includes. After a bit of hunting and looking through the web.config files underneath the &#8230; <a href="http://davidmuto.com/2011/03/07/global-namespace-includes-with-mvc3-and-razor/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidmuto.com&amp;blog=19878726&amp;post=4&amp;subd=davidmuto&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>While I&#8217;m loving MVC3 and the Razor view engine, I was sorely disappointed when I couldn&#8217;t use the system.web/pages/namespaces collection in web.config to add global namespace includes.</p>
<p>After a bit of hunting and looking through the web.config files underneath the views folder (in each Area), I found that this can be accomplished by adding the following to the root web.config file:</p>
<p><pre class="brush: xml;">
&lt;configSections&gt;
    &lt;sectionGroup name=&quot;system.web.webPages.razor&quot; type=&quot;System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35&quot;&gt;
      &lt;section name=&quot;pages&quot; type=&quot;System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35&quot; requirePermission=&quot;false&quot; /&gt;
    &lt;/sectionGroup&gt;
  &lt;/configSections&gt;

  &lt;system.web.webPages.razor&gt;
    &lt;pages pageBaseType=&quot;System.Web.Mvc.WebViewPage&quot;&gt;
      &lt;namespaces&gt;
        &lt;add namespace=&quot;System.Web.Mvc&quot; /&gt;
        &lt;add namespace=&quot;System.Web.Mvc.Ajax&quot; /&gt;
        &lt;add namespace=&quot;System.Web.Mvc.Html&quot; /&gt;
        &lt;add namespace=&quot;System.Web.Routing&quot; /&gt;
      &lt;/namespaces&gt;
    &lt;/pages&gt;
  &lt;/system.web.webPages.razor&gt;
</pre></p>
<div id="_mcePaste" class="mcePaste" style="position:absolute;width:1px;height:1px;overflow:hidden;top:0;left:-10000px;">﻿</div>
<p>Now you can add any namespaces you require under the new razor namespaces section.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidmuto.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidmuto.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidmuto.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidmuto.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidmuto.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidmuto.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidmuto.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidmuto.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidmuto.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidmuto.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidmuto.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidmuto.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidmuto.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidmuto.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=davidmuto.com&amp;blog=19878726&amp;post=4&amp;subd=davidmuto&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://davidmuto.com/2011/03/07/global-namespace-includes-with-mvc3-and-razor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/2cf9c90cc7eb61ee14be216aea33a2be?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">davidmuto</media:title>
		</media:content>
	</item>
	</channel>
</rss>
