TinyMCE Javascript WYSIWYG Editor in MVC3 application

This is what the output textarea looks like when you use the TinyMCE editor in MVC3 application

Text Editor

Step 1: Download the tinymce jquery version from http://www.tinymce.com/ and add the scripts to the required folder.

Step 2: Add the below scripts to the view where you want to display the word editor. Also make sure that the scripts in tiny_mce are also included to the solution.

<script type=”text/javascript” src=”@Url.Content(“~/Scripts/tinymce/jquery.tinymce.js”)”></script>

<script type=”text/javascript” src=”@Url.Content(“~/Scripts/tinymce/tiny_mce.js”)”></script>

<script type=”text/javascript”>



theme :“advanced”,

plugins :“autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,advlist”,

theme_advanced_buttons1 :“save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect”,

theme_advanced_buttons2 :“cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor”,

theme_advanced_buttons3 :“tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen”,

theme_advanced_buttons4 :“insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak”,

theme_advanced_toolbar_location :“top”,

theme_advanced_toolbar_align :“left”,

theme_advanced_statusbar_location :“bottom”,

theme_advanced_resizing :true,



Step3: Now use @Html.TextAreaFor(model => model.TextDescription, new { cols=“85”, rows=“8”}) 

in the view to display and return formatted text to the controller.

Step4: Make sure that the action has [ValidateInput(false)] attribute added to it.  Just in case, the model has <p> or other content that might be red flagged.


Navigating to specific part of a view in mvc3

I have a requirement to navigate to a specific section of a view when the page is loaded. This is how I ended up doing it.

Controller: In my controller’s action, I am saving the id of anchor tag to be clicked on page load into ViewData.

View: id of the anchor tag to be clicked to navigate within the document is saved in a hidden field. On page load java script function, I am getting the anchor tag from the hidden <p> control and clicking on it to navigate to the desired position.