Rich Text Editor for MVC

2023-02-16,,,

在网站开发中难免会用到富文本编辑器,本文将介绍一款富文本编辑器(在线HTML编辑器) Rich Text Editor ,简要说明一下其在MVC中的使用。

具体使用情况和下载地址请参考:http://www.richtexteditor.com/

一、准备工作

1.在上述网站中下载此编辑器的开发包,解压后会发现有几个文件夹,如图:

我使用的是Asp.Net MVC4 版本,开发是c#,请大家选择适合自己的开发包。

2.进入该文件(mvc4_cs_razor),把 richtexteditor 开发包文件夹复制到你的项目根目录下,并复制 bin 目录下的几个dll文件至你的项目bin文件夹下,如图:

复制后,项目下就有了这些文件,如图:

3. 添加对该编辑器DLL的引用(两个DLL:NetSpell.SpellChecker.dll 和 RichTextEditor.dll),如图:

4.修改配置文件:

IIS5,IIS6,IIS7 经典模式使用如下配置信息

<configuration>
<system.web>
<httpModules>
<add name="UploadModule" type="RTE.UploadModule,RichTextEditor"/>
</httpModules>
</system.web>
</configuration>

IIS7 集成模式使用如下配置信息

<configuration>
<system.webServer>
<modules>
<add name="UploadModule" type="RTE.UploadModule,RichTextEditor"/>
</modules>
</system.webServer>
</configuration>

二、在代码中如何使用

做完上述准备工作后,就开始在代码中使用了

1.发布新闻时

[CheckLoginAttributer]
public ActionResult Create()
{
Editor Editor1 = new Editor(System.Web.HttpContext.Current, "Content");
Editor1.MvcInit();
ViewBag.Editor = Editor1.MvcGetString(); return View();
}

图解:

2.编辑新闻时,新闻内容是怎么赋值的呢?

//
// GET: /News/Edit/5
[CheckLoginAttributer]
public ActionResult Edit(Guid id)
{
News news = db.News.Find(id);
if (news == null)
{
return HttpNotFound();
} Editor Editor1 = new Editor(System.Web.HttpContext.Current, "Content");
Editor1.Text = news.Content;
Editor1.MvcInit();
ViewBag.Editor = Editor1.MvcGetString(); return View(news);
}

图解:

Rich Text Editor for MVC的相关教程结束。

《Rich Text Editor for MVC.doc》

下载本文的Word格式文档,以方便收藏与打印。