After learning ASP. net mvc Framework for a while, I want to use ASP. NET MVC Framework as a blog Program . After searching for half a day, I did not find a good rich text editor that can be called directly under the MVC framework. Some components of the original Asp.net webform can be referenced directly in the MVC framework, but it is not very comfortable, so I plan to write one by myself. I first thought of FCKeditor. It is actually a platform-independent Rich Text Editor that can run in Java, ASP, and Asp.net webform environments. Of course, it can also be used in ASP.. Net MVC framework. I tried it myself today and found that the effect was good.
Most of the functions of the fck editor are completed by client JS scripts. The only thing that requires interaction with the server is to browse and upload files from the server, I also created a page for browsing files based on the MVC framework.
: Mvcfckeditor.rar)
Usage:
1. Copy all the files in the compressed package to the root directory of your MVC application.
2. on the page to use the fck Editor, add: <SCRIPT type = "text/JavaScript" src = "/fckeditor2.3.6/FCKeditor. js"> </SCRIPT>
3. You can use an extension method of htmlhelper at the position where you want to use the fck editor. (It is very convenient to get the editor prompt in vs2008)
<% = Html. FCKeditor ("fcktextbox") %>
It has three reloads:
Public static string FCKeditor (this htmlhelper HTML, string name );
Public static string FCKeditor (this htmlhelper HTML, string name, fckconfig objfckconfig );
Public static string FCKeditor (this htmlhelper HTML, string name, string value, fckconfig objfckconfig );
Name: the name of the control. It is the same as other HTML controls. You can use request. Form ["name"] in the background to obtain the value.
Objfckconfig: Specifies the fck attribute configuration class, which includes common length, width, height, skin, and style. (Currently, more configuration attributes can be added only after these attributes are defined, which makes the application more flexible.) If this parameter is not configured, the default value is used.
<% = Html. FCKeditor ("fcktextbox", new fckconfig {width = "600", Height = "500", skin = fckskin. office2003, toolbarset = fcktoolbarset. basic}) %>
Value: the value of this control. You can specify this value. If this value is not specified, the value in viewdata with the same name is used by default. This is similar to other htmlhelper.
Control the location of uploaded files:
By default, all uploaded files are uploaded"Website and directory/userfiles"ContentsDirectory. If you reference mvcfckeditor. dll in the program and implement the getuserfilespath method in the abstract class mvcfckeditor. components. fckprovider, you can define the upload path by yourself. For example:
Testfckprovider
Namespace Mcvtest. Provider
{
Public Class Testfckprovider: fckprovider
{
// Allows different users to upload files to different directories.
Public Override String Getuserfilespath ()
{
Httpcontext Context = Httpcontext. Current;
If (Context. User ! = Null && Context. User. Identity ! = Null && Context. User. Identity. isauthenticated)
{
// Of course, I need to judge whether the user name complies with the folder rules. Here is just an example. You can use the user ID or other methods to achieve this.
Return " /Userfiles/ " + Context. User. Identity. Name;
}
Else
{
Return " /Userfiles/Anonymous " ;
}
}
}
}
Then we need to configure it in Web. config and add it to the etettings node:
<Deleetask>
<Add key = "fckprovider" value = "mcvtest. provider. testfckprovider, mcvtest"/>
</Appsettings>
In the future, I will define more abstract methods to achieve more flexible configuration, such as determining whether a user can upload files, how many types of files can be uploaded, and so on...
In this way, our program can run. If you have any suggestions or questions, please leave a message and I will continue to improve the mvcfckeditor function.
Download Demo: mvctest