<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.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>SuperSKa Weblog : FckEditor</title><link>http://msmvps.com/blogs/superska/archive/tags/FckEditor/default.aspx</link><description>Tags: FckEditor</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>Using FCK Editor with ASP.NET MVC</title><link>http://msmvps.com/blogs/superska/archive/2009/04/06/using-fck-editor-with-asp-net-mvc.aspx</link><pubDate>Mon, 06 Apr 2009 11:22:00 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1685065</guid><dc:creator>Stefan Kamphuis</dc:creator><slash:comments>7</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://msmvps.com/blogs/superska/rsscomments.aspx?PostID=1685065</wfw:commentRss><comments>http://msmvps.com/blogs/superska/archive/2009/04/06/using-fck-editor-with-asp-net-mvc.aspx#comments</comments><description>&lt;p&gt;First of, what is this &lt;a title="FCK Editor" href="http://www.fckeditor.net/" target="_blank"&gt;FCKEditor&lt;/a&gt;? Well, it&amp;#39;s an HTML Text Editor. It&amp;#39;s free and open source, cross browser, extensible and there are probably quite a few more buzzwords applicable. Oh... and it&amp;#39;s also the default HTML Text Editor provided with &lt;a title="DotNetNuke" href="http://www.dotnetnuke.com/" target="_blank"&gt;DotNetNuke&lt;/a&gt;. Fck Editor is soon to be replaced by &lt;a title="CK Editor" href="http://ckeditor.com" target="_blank"&gt;CK Editor&lt;/a&gt; but I&amp;#39;ll stick with Fck for now. CK will work mostly the same though.&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/superska/image_5F00_2.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;border-top:0px;border-right:0px;" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/superska/image_5F00_thumb.png" align="right" border="0" width="244" height="213" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;First, you&amp;#39;ll need to &lt;a title="download Fck Editor" href="http://www.fckeditor.net/download" target="_blank"&gt;download Fck Editor&lt;/a&gt;. Unzip the downloaded file to see what&amp;#39;s in there.&lt;/p&gt;
&lt;p&gt;You&amp;#39;ll need to copy the &amp;quot;editor&amp;quot; folder over to you Contents folder in you ASP.NET MVC website. I chose the path &amp;quot;/Content/Js/ Fck&amp;quot; to paste it in.&lt;/p&gt;
&lt;p&gt;Two other files you might want to copy over to this same folder are in the root of the downoaded zipfile: &lt;i&gt;fckeditor.js&lt;/i&gt; and &lt;i&gt;fckconfig.js&lt;/i&gt;. The latter is expected by the editor and (suprisingly) contains configuration settings for the editor, while the first contains a few nice javascript functions to instanciate the editor.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/superska/image_5F00_4.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;border-top:0px;border-right:0px;" alt="image" src="http://msmvps.com/cfs-file.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/superska/image_5F00_thumb_5F00_1.png" border="0" width="244" height="198" /&gt;&lt;/a&gt;&amp;nbsp; &lt;/p&gt;
&lt;p&gt;Next, include the fckeditor.js file in your page:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;src&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;&amp;lt;%= Url.Content(&amp;quot;&lt;/span&gt;~/&lt;span class="attr"&gt;Content&lt;/span&gt;/&lt;span class="attr"&gt;Js&lt;/span&gt;/&lt;span class="attr"&gt;fck&lt;/span&gt;/&lt;span class="attr"&gt;fckeditor&lt;/span&gt;.&lt;span class="attr"&gt;js&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;quot;) %&amp;gt;&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;text/javascript&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;All set. Now you&amp;#39;ll need to add a textarea to your page:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= Html.TextArea(&lt;span class="str"&gt;&amp;quot;FckEditor1&amp;quot;&lt;/span&gt;, &amp;quot;Some Value&amp;quot;, &lt;br /&gt;  &lt;span class="kwrd"&gt;new&lt;/span&gt; { @name=&lt;span class="str"&gt;&amp;quot;FckEditor1&amp;quot;&lt;/span&gt; })&lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Important thing here, is the name property of the TextArea being set to the same value as the Id of it.&lt;/p&gt;
&lt;p&gt;To finish the client side of things off, you&amp;#39;l need to add some javascript to turn the textarea into a FckEditor at runtime. This can be copied from the samples of course, except for the Url.Contents part:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;text/javascript&amp;quot;&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br /&gt;window.onload = &lt;span class="kwrd"&gt;function&lt;/span&gt;()&lt;br /&gt;{&lt;br /&gt;  &lt;span class="kwrd"&gt;var&lt;/span&gt; sBasePath = &lt;span class="str"&gt;&amp;#39;&amp;lt;%= Url.Content(&amp;quot;~/Content/Js/Fck/&amp;quot;) %&amp;gt;&amp;#39;&lt;/span&gt;;&lt;br /&gt;&lt;br /&gt;  &lt;span class="kwrd"&gt;var&lt;/span&gt; oFCKeditor = &lt;span class="kwrd"&gt;new&lt;/span&gt; FCKeditor( &lt;span class="str"&gt;&amp;#39;FckEditor1&amp;#39;&lt;/span&gt; ) ;&lt;br /&gt;  oFCKeditor.BasePath = sBasePath ;&lt;br /&gt;  oFCKeditor.ReplaceTextarea() ;&lt;br /&gt;}&lt;br /&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Now, to prevent the server error &amp;quot;&lt;b&gt;A potentially dangerous Request.Form value was detected from the client &lt;/b&gt;&amp;quot;, you should add the attribute &amp;quot;ValidateInput&amp;quot; to your controller&amp;#39;s action method like this&amp;quot;:&lt;/p&gt;
&lt;pre class="csharpcode"&gt;[ValidateInput(&lt;span class="kwrd"&gt;false&lt;/span&gt;)]&lt;br /&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult Save(&lt;span class="kwrd"&gt;int&lt;/span&gt; id)&lt;br /&gt;{&lt;br /&gt;    ...&lt;br /&gt;}&lt;/pre&gt;
&lt;p&gt;With this, you&amp;#39;re all set. The contents of the TextArea field you started out with, will contain the contents of the FckEditor control.&lt;/p&gt;
&lt;p&gt;Have fun! &lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1685065" width="1" height="1"&gt;</description><category domain="http://msmvps.com/blogs/superska/archive/tags/ASP.NET+MVC/default.aspx">ASP.NET MVC</category><category domain="http://msmvps.com/blogs/superska/archive/tags/FckEditor/default.aspx">FckEditor</category></item></channel></rss>