Use FCK in ASP. NET MVC

Source: Internet
Author: User

Asp.net
Reference fck js and jquery. js on the page

View call

@ Html. FckText ("Content2", Model. Content2)

 

Backend Extension Method

Public static MvcHtmlString FckText (this System. Web. Mvc. HtmlHelper helper, string name, string val, string width = "1500", string height = "400 ")
{
If (string. IsNullOrEmpty (name ))
{
Return MvcHtmlString. Create ("the name attribute is required ");
}
Int thm = DateTime. Now. Millisecond;
String html = @"
<Script type = "" text/javascript "">
$ (Function (){
Var oFCKeditor2 "+ thm + @" = new FCKeditor ('"+ name + @"');
// Height
OFCKeditor2 "+ thm + @". Width = "+ width + @";
// Width
OFCKeditor2 "+ thm + @". Height = "+ height + @";
// Initialize the content
OFCKeditor2 "+ thm + @". value = "" write you message here! "";
OFCKeditor2 "+ thm + @". ReplaceTextarea ();
})
</Script>
<Textarea rows = "10" "cols =" 20 "" name = "+ name + @" id = "+ name + @"""> "+ val + @" </textarea>

";
Return MvcHtmlString. Create (html );
}

 


Common JS methods of FCK

<Script type = "text/javascript">
Function getEditorHTMLContents (EditorName ){
Var oEditor = FCKeditorAPI. GetInstance (EditorName );
Return (oEditor. GetXHTML (true ));
}
// Get the text content in the editor more self Forum: http://www.52mvc.com/showtopic-1382.aspx
Function getEditorTextContents (EditorName ){
Var oEditor = FCKeditorAPI. GetInstance (EditorName );
Return (oEditor. EditorDocument. body. innerText );
}
// Set the content in the editor
Function SetEditorContents (EditorName, ContentStr ){
Var oEditor = FCKeditorAPI. GetInstance (EditorName );
OEditor. SetHTML (ContentStr );
}
</Script>

 

 


Principle

Basic usage
1. First, log on to the official website to download the package, for example, FCKeditor_2.6.4.1.zip.
2. decompress the package and generate a directory. fckeditor copies the directory to the root directory of the project.
3. reference the toolkit on the page. use Javascript reference here, and use the FCK tag reference.
<Script type = "text/javascript" src = "fckeditor/fckeditor. js"> </script>
4. Define a text compilation field and load the event when the form is loaded:

<Script type = "text/javascript">
Window. onload = function (){
Var oFCKeditor = new FCKeditor ('mydata ');

// Compiler basic path

OFCKeditor. BasePath = "/fckeditor /";

// Height: www.2cto.com

OFCKeditor. Width = 600;

// Width

OFCKeditor. Height = 400;

// Initialize the content

OFCKeditor. value = "write you message here! ";
OFCKeditor. ReplaceTextarea ();

}

</Script>

<Textarea rows = "10" cols = "20" name = "myData" id = "myData">

</Textarea>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.