Rich Text Editor for MVC

在网站开发中难免会用到富文本编辑器,本文将介绍一款富文本编辑器(在线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);
        }
复制代码


图解:

 

 

posted @   萌浩  阅读(812)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示