<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://fusionovation.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Matt Palmer’s Blog</title><link>http://fusionovation.com/blogs/mpalmer/default.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 20917.1142)</generator><item><title>Adding a rich text editor to ASP.NET MVC using strongly typed helpers, DataAnnotations &amp; jQuery</title><link>http://fusionovation.com/blogs/mpalmer/archive/2010/02/15/adding-a-rich-text-editor-to-asp-net-mvc-using-strongly-typed-helpers-dataannotations-amp-jquery.aspx</link><pubDate>Mon, 15 Feb 2010 19:07:00 GMT</pubDate><guid isPermaLink="false">3873cc62-7325-4c9d-b6a6-c9952780d65c:106</guid><dc:creator>mpalmer</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://fusionovation.com/blogs/mpalmer/rsscomments.aspx?PostID=106</wfw:commentRss><comments>http://fusionovation.com/blogs/mpalmer/archive/2010/02/15/adding-a-rich-text-editor-to-asp-net-mvc-using-strongly-typed-helpers-dataannotations-amp-jquery.aspx#comments</comments><description>&lt;p&gt;You may have read about the new &lt;a href="http://weblogs.asp.net/scottgu/archive/2010/01/10/asp-net-mvc-2-strongly-typed-html-helpers.aspx"&gt;strongly-typed helpers in ASP.NET MVC 2&lt;/a&gt;. In addition to the HTML element helpers like &lt;span class="code"&gt;Html.TextBoxFor()&lt;/span&gt;, you can use the more generic &lt;span class="code"&gt;Html.EditorFor()&lt;/span&gt; to build your own template for editing a custom data type. In this post, I&amp;#39;ll show you how to create a single template you can use for any forms that need a rich text editor.&lt;/p&gt;

&lt;h3&gt;UIHints using Using DataAnnotations&lt;/h3&gt;
&lt;p&gt;First, we need to specify the type of data we&amp;#39;ll be building a template for. We&amp;#39;ll use a simplified CMS model as an example:&lt;/p&gt;
&lt;pre&gt;
public class CMSPage
{
    public CMSPage() { }

    string Title { get; set; }
    string URL { get; set; }
    string Content { get; set; }
}
&lt;/pre&gt;

&lt;p&gt;Using DataAnnotations, we can specify the type of each of these elements:&lt;/p&gt;

&lt;pre&gt;
public class CMSPage
{
    public CMSPage() { }

    [DataType(DataType.Text)]
    string Title { get; set; }

    [DataType(DataType.Url)]
    string URL { get; set; }

    [DataType(DataType.Html)]
    string Content { get; set; }
}
&lt;/pre&gt;

&lt;p&gt;We have already provided enough information for the &lt;span class="code"&gt;EditorFor&lt;/code&gt; to build a decent edit form for our &lt;span class="code"&gt;CMSPage&lt;/span&gt; object&amp;mdash;but with a UIHint we can make this even better:

&lt;pre&gt;
public class CMSPage
{
    public CMSPage() { }

    [DataType(DataType.Text)]
    string Title { get; set; }

    [DataType(DataType.Url)]
    string URL { get; set; }

    [DataType(DataType.Html)]
    [UIHint(&amp;quot;Html&amp;quot;)]
    string Content { get; set; }
}
&lt;/pre&gt;

&lt;p&gt;&lt;span class="code"&gt;EditorFor&lt;/span&gt; now knows we want to use the &amp;quot;Html&amp;quot; template for the &lt;span class="code"&gt;Content&lt;/span&gt; field&amp;mdash;now we just need to create the template.&lt;/p&gt;

&lt;h3&gt;Custom EditorTemplates&lt;/h3&gt;
&lt;p&gt;Create a new folder in &lt;span class="code"&gt;Views/Shared&lt;/span&gt; called &lt;span class="code"&gt;EditorTemplates&lt;/span&gt;, and create a new partial view, &lt;span class="code"&gt;Html.ascx&lt;/span&gt;,  in that folder. Since this template will be used for editing HTML, we can use &lt;span class="code"&gt;string&lt;/span&gt; as the type.&lt;/p&gt;

&lt;pre&gt;
&amp;lt;%@ Control Language=&amp;quot;C#&amp;quot; Inherits=&amp;quot;System.Web.Mvc.ViewUserControl&amp;lt;String&amp;gt;&amp;quot; %&amp;gt;
&amp;lt;%= Html.TextArea(&amp;quot;&amp;quot;, Model, new { @class = &amp;quot;html&amp;quot; })%&amp;gt;
&lt;/pre&gt;

&lt;p&gt;Now the &lt;span class="code"&gt;EditorFor&lt;/span&gt; helper will use our new &lt;span class="code"&gt;Html.ascx&lt;/span&gt; template for any fields we&amp;#39;ve specified to be HTML using the &lt;span class="code"&gt;UIHint&lt;/span&gt; attribute. Currently our template is just a textarea with the CSS class &lt;span class="code"&gt;html&lt;/span&gt; applied, but with a little jQuery and progressive enhancement we can improve on that.

&lt;h3&gt;Upgrading your textarea with markItUp!&lt;/h3&gt;
&lt;p&gt;&lt;a href="http://markitup.jaysalvat.com"&gt;markItUp!&lt;/a&gt; is a jQuery plugin that lets you turn any textarea into a rich text editor for any number of text formats&amp;mdash;we&amp;#39;ll be looking at an editor for HTML, but there are markItUp! &lt;a href="http://markitup.jaysalvat.com/downloads/"&gt;sets available&lt;/a&gt; for formats like Textile, markdown, wikis, and many others. After &lt;a href="http://markitup.jaysalvat.com/downloads/"&gt;downloading&lt;/a&gt; the latest release and the Html set, add the required CSS and JavaScript references:&lt;/p&gt;

&lt;pre&gt;
&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; type=&amp;quot;text/css&amp;quot; href=&amp;quot;markitup/skins/markitup/style.css&amp;quot; /&amp;gt;
&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; type=&amp;quot;text/css&amp;quot; href=&amp;quot;markitup/sets/html/style.css&amp;quot; /&amp;gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;jquery.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;markitup/jquery.markitup.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;markitup/sets/html/set.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;
&lt;/pre&gt;

&lt;p&gt;Now all we need to upgrade our textarea to a rich text editor is:&lt;/p&gt;

&lt;pre&gt;
jQuery(function ($) {
    $(&amp;#39;textarea.html&amp;#39;).markItUp(mySettings);
});
&lt;/pre&gt;

&lt;p&gt;
So what are the advantages of this approach?
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Reusable&lt;/strong&gt; - all you need to do to add the same editor support to another field on any model is to add the appropriate &lt;span class="code"&gt;UIHelper&lt;/span&gt; attribute. You could even develop several templates like this to use as a standard base project.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;DRY&lt;/strong&gt; - there is exactly one place to change the editor for all &amp;quot;Html&amp;quot; type fields.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Consistent&lt;/strong&gt; - you can be sure that all &amp;quot;Html&amp;quot; fields will have the same editor control.&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;&lt;img src="http://fusionovation.com/aggbug.aspx?PostID=106" width="1" height="1"&gt;</description><category domain="http://fusionovation.com/blogs/mpalmer/archive/tags/DataAnnotations/default.aspx">DataAnnotations</category><category domain="http://fusionovation.com/blogs/mpalmer/archive/tags/markItUp_2100_/default.aspx">markItUp!</category><category domain="http://fusionovation.com/blogs/mpalmer/archive/tags/ASP.NET+MVC/default.aspx">ASP.NET MVC</category><category domain="http://fusionovation.com/blogs/mpalmer/archive/tags/Helpers/default.aspx">Helpers</category><category domain="http://fusionovation.com/blogs/mpalmer/archive/tags/MVC/default.aspx">MVC</category></item><item><title>Quality is in the Details</title><link>http://fusionovation.com/blogs/mpalmer/archive/2010/01/13/Quality-is-in-the-Details.aspx</link><pubDate>Wed, 13 Jan 2010 20:36:00 GMT</pubDate><guid isPermaLink="false">3873cc62-7325-4c9d-b6a6-c9952780d65c:104</guid><dc:creator>mpalmer</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://fusionovation.com/blogs/mpalmer/rsscomments.aspx?PostID=104</wfw:commentRss><comments>http://fusionovation.com/blogs/mpalmer/archive/2010/01/13/Quality-is-in-the-Details.aspx#comments</comments><description>&lt;p&gt;I recently read &lt;a href="http://www.contrast.ie/blog/the-thickness-of-napkins/"&gt;a great post&lt;/a&gt; that tied chef Gordon Ramsey&amp;#39;s obsessive nature to software quality:&lt;/p&gt;

&lt;blockquote&gt;
Gordon Ramsey, in his auto-biography, defended his obsessive perfectionist nature, arguing he has to obsess. You don’t win Michelin stars without it.
&lt;blockquote&gt;
“It doesn’t matter how amazing the steak is, if it’s served on a cold plate it’s crap. If it’s served with a dull knife it’s crap. If the gravy isn’t piping hot, it’s crap. If you’re eating it on an uncomfortable chair, it’s crap. If it’s served by an ugly waiter who just came in from a smoke break, it’s crap. Because I care about the steak, I have to care about everything around it. “
&lt;/blockquote&gt;
The parallels in software are obvious. If you see a few lines of atrocious code, you can make a judgement about the programmer. By judging the programmer, you can judge his boss, and by judging his boss you can judge the company. That’s the nature of fractals. The desire for quality trickles down to everything from making sure that the homepage photo isn’t blurry all the way through to making sure that font in Christmas card is correct. As Aristotle said, excellence is not an act but a habit.
&lt;/blockquote&gt;

&lt;p&gt;Attention to detail is vital. Thomas Keller, the only American with two three-star restaurants, is famously obsessed with the details. In &lt;em&gt;The Soul of a Chef&lt;/em&gt;, Michael Ruhlman notes that Keller stores his fish on ice in the direction they swim in the ocean. His serving staff are trained by ballet instructors. He has banned the use of tongs in his kitchen, believing they harm the food. He has stopped to correct kitchen staff when he believed they were not gentle enough with the loaf when slicing bread, and has instructed his servers to replace your bread if it cools before you are ready to eat it. He even inspects every plate that comes back to the kitchen, looking for anything that wasn&amp;#39;t eaten.&lt;/p&gt;

&lt;p&gt;Chef David Chang of Momofuku turned a tiny noodle shop into one of the most popular restaurants in New York by holding himself to a higher standard:
&lt;blockquote&gt;
Just because we&amp;#39;re not Per Se, just because we&amp;#39;re not Daniel, just because we&amp;#39;re not a four-star restaurant, why can&amp;#39;t we have the same ... standards? ... I know we&amp;#39;ve won awards, all this stuff, but it&amp;#39;s not because we&amp;#39;re doing something special—I believe it&amp;#39;s really because we care more than the next guy.
&lt;/blockquote&gt;

&lt;p&gt;It&amp;#39;s easy to see who pays attention to detail in the software world:&lt;/p&gt;
&lt;a href="http://stuffthathappens.com/blog/2008/03/05/simplicity/"&gt;&lt;img src="http://fusionovation.com/blogs/mpalmer/googleproduct.jpg" alt="Typical Apple Product, A Google Product, Your Company&amp;#39;s App" style="margin:0 0 10px 40px;" /&gt;&lt;/a&gt;

&lt;p&gt;How much attention are you paying to the details of your application? You may not be building the next Apple product, but why not hold yourself to the same standards?&lt;/p&gt;&lt;img src="http://fusionovation.com/aggbug.aspx?PostID=104" width="1" height="1"&gt;</description><category domain="http://fusionovation.com/blogs/mpalmer/archive/tags/software/default.aspx">software</category><category domain="http://fusionovation.com/blogs/mpalmer/archive/tags/quality/default.aspx">quality</category></item><item><title>Is your app ready for Windows 7?</title><link>http://fusionovation.com/blogs/mpalmer/archive/2009/06/25/is-your-app-ready-for-windows-7.aspx</link><pubDate>Thu, 25 Jun 2009 13:10:00 GMT</pubDate><guid isPermaLink="false">3873cc62-7325-4c9d-b6a6-c9952780d65c:69</guid><dc:creator>mpalmer</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://fusionovation.com/blogs/mpalmer/rsscomments.aspx?PostID=69</wfw:commentRss><comments>http://fusionovation.com/blogs/mpalmer/archive/2009/06/25/is-your-app-ready-for-windows-7.aspx#comments</comments><description>&lt;p&gt;
&lt;a href="http://windowsteamblog.com/blogs/windows7/archive/2009/06/02/the-date-for-general-availability-ga-of-windows-7-is.aspx" target="_blank"&gt;Windows 7 will be available in stores October 22&lt;/a&gt; - is your app ready? Here&amp;#39;s a quick checklist to make sure your application takes full advantage of the new features in Windows 7:
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Test for compatibility&lt;/strong&gt;&lt;br /&gt;
Tools like &lt;a href="http://go.microsoft.com/fwlink/?linkid=11573" target="_blank"&gt;Application Verifier&lt;/a&gt; can help you ensure your application has a smooth transition to Windows 7. Learn more about application compatibility at the &lt;a href="http://msdn.microsoft.com/en-us/windows/aa904987.aspx" target="_blank"&gt;Windows Developer Center&lt;/a&gt;.
&lt;br /&gt;&lt;br /&gt;
&lt;/li&gt;

&lt;li&gt;&lt;strong&gt;Add support for Libraries&lt;/strong&gt;&lt;br /&gt;
&lt;a href="http://windowsteamblog.com/blogs/developers/archive/2009/04/06/understanding-windows-7-libraries.aspx" target="_blank"&gt;Windows 7 Libraries&lt;/a&gt; allow users to group similar files across several folders. When your application works with Libraries, you can suggest a reasonable place for users to save their work, or you can even create Libraries specific to your application. &lt;a href="http://windowsteamblog.com/blogs/developers/archive/2009/04/16/light-up-with-windows-7-libraries.aspx"&gt;Check out three strategies for making your application Libraries-aware&lt;/a&gt; on the &lt;a href="http://windowsteamblog.com/blogs/developers/default.aspx" target="_blank"&gt;Windows 7 for Developers&lt;/a&gt; blog.
&lt;br /&gt;&lt;br /&gt;
&lt;/li&gt;

&lt;li&gt;&lt;strong&gt;Use the new Ribbon API&lt;/strong&gt;&lt;br /&gt;
The Ribbon menu that was introduced with Office 2007 is &amp;quot;the next generation user experience&amp;quot; for Windows applications. Grab the &lt;a href="http://www.microsoft.com/downloadS/details.aspx?familyid=141E13E8-B10B-4356-AAA5-609B2981574A&amp;amp;displaylang=en" target="_blank"&gt;sample code&lt;/a&gt; or check out the &lt;a href="http://channel9.msdn.com/posts/yochay/Windows-7-Ribbon-Deep-Dive/" target="_blank"&gt;Windows 7 Ribbon series on Channel9&lt;/a&gt; to find out how to use the ribbon in your app.
&lt;br /&gt;&lt;br /&gt;
&lt;/li&gt;

&lt;li&gt;&lt;strong&gt;Integrate with the web using Accelerators&lt;/strong&gt;&lt;br /&gt;
Using the &lt;a href="http://msdn.microsoft.com/en-us/library/dd565720(VS.85).aspx" target="_blank"&gt;Windows 7 Accelerator Platform&lt;/a&gt; you can make sharing your application&amp;#39;s content with sites like Facebook and Live Maps just a click away. You can even create your own accelerators to make use of your product&amp;#39;s website.
&lt;br /&gt;&lt;br /&gt;
&lt;/li&gt;

&lt;li&gt;&lt;strong&gt;Speed up your code with the new Windows 7 Instrumentation updates&lt;/strong&gt;&lt;br /&gt;
You&amp;#39;ve probably heard by now that &lt;a href="http://www.maximumpc.com/article/news/how_fast_is_windows_7_faster_than_you_think" target="_blank"&gt;Windows 7 is faster than XP or Vista&lt;/a&gt; - can your app keep up? The new Windows 7 Intrumentation features and updates to Event Tracing for Windows (ETW) can make finding the bottlenecks in your code easier than ever. The &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=12100526-ed26-476b-8e20-69662b8546c1&amp;amp;displaylang=en" target="_blank"&gt;Windows 7 RC Training Kit for Developers&lt;/a&gt; has hands-on labs to try out the new features.
&lt;br /&gt;&lt;br /&gt;
&lt;/li&gt;

&lt;li&gt;&lt;strong&gt;Qualify for the &amp;quot;Compatible with Windows 7&amp;quot; logo&lt;/strong&gt;&lt;br /&gt;
Check out &lt;a href="http://msdn.microsoft.com/en-us/windows/dd203105.aspx" target="_blank"&gt;the Windows 7 Software Logo Program&lt;/a&gt; to find out how your application can qualify for the &amp;quot;Compatible with Windows 7&amp;quot; logo - which will also net you a priority listing on the &lt;a href="http://www.microsoft.com/windows/compatibility/windows-7/" target="_blank"&gt;Windows 7 Compatibility Center&lt;/a&gt;.
&lt;br /&gt;&lt;br /&gt;
&lt;/li&gt;

&lt;/ul&gt;&lt;img src="http://fusionovation.com/aggbug.aspx?PostID=69" width="1" height="1"&gt;</description><category domain="http://fusionovation.com/blogs/mpalmer/archive/tags/Windows+7/default.aspx">Windows 7</category></item></channel></rss>
