主题: KindEditor取值与赋值的问题
作者: 墨竹蛮, 发布日期: 2013-08-09 15:01:35, 浏览数: 7684

我的项目使用的是mvc框架,需要时间公告信息发布。

问题1、

        我使用KindEditor编写内容,然后传至controller后台数据的时候只可以传文本格式的数据,但不可以传html带标签格式的数据。

问题2、

        目前我是把文本格式的内容保存到一张html页面上了,我需要通过那张html页面获取到我之前保存的内容,可是获取到的是以字符串形式的显示出来了,之前的换行一类的操作都不存在了。

        代码附上:

 

//这是我获取到值之后保存并生成html页面 
 public ActionResult Create(ZAJGGG entity)
        {           
            if (entity != null && ModelState.IsValid)
            {
                string currentPerson = GetCurrentPerson();
                //entity.CreateTime = DateTime.Now;
                //entity.CreatePerson = currentPerson;
                string uploadPath = Server.MapPath("/");                            
                //获取模板的路径
                string path = Server.MapPath("/Test.htm");
                //获取编码模式
                
                Encoding code = Encoding.GetEncoding("UTF-8");
                StreamReader sr = null;
                StreamWriter sw = null;
                string str = null;
                //读取模板
                try
                {
                    sr = new StreamReader(path, code);
                    str = sr.ReadToEnd();
                }
                catch
                {

                    throw;
                }
                finally {
                    sr.Close();
                }


                //按年月生成文件夹
                string folderName = DateTime.Now.ToString("yyyyMMdd", DateTimeFormatInfo.InvariantInfo);
                //生成新文件名
                string fileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff", DateTimeFormatInfo.InvariantInfo) + ".html";
                //判断是否存在文件名
                if (!Directory.Exists(uploadPath + "htmlgg\\" + folderName))
                {
                    Directory.CreateDirectory(uploadPath + "htmlgg\\" + folderName);
                }
                 

                //获取动态数据 
                string changeText = entity.HIDGGNR;
                //用动态数据替换模板中数据   
                str = str.Replace("$content$", changeText);
                  //生成静态文件      
        try
        {
            sw = new StreamWriter(uploadPath + "htmlgg\\" + folderName+"\\" + fileName, false, code);
            sw.Write(str);
            sw.Flush();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            sw.Close();
        }

        string url =  "../../htmlgg/" + folderName + "/" + fileName;
                entity.GGNR = url;




                entity.FQRQ = DateTime.Now;
                entity.ZAJGGGID = Result.GetNewId();   
                string returnValue = string.Empty;
                if (m_BLL.Create(ref validationErrors, entity))
                {
                    LogClassModels.WriteServiceLog(Suggestion.InsertSucceed  + ",治安监管公告的信息的Id为" + entity.ZAJGGGID,"治安监管公告"
                        );//写入日志 
                    return Json(Suggestion.InsertSucceed);
                }
                else
                { 
                    if (validationErrors != null && validationErrors.Count > 0)
                    {
                        validationErrors.All(a =>
                        {
                            returnValue += a.ErrorMessage;
                            return true;
                        });
                    }
                    LogClassModels.WriteServiceLog(Suggestion.InsertFail + ",治安监管公告的信息," + returnValue,"治安监管公告"
                        );//写入日志                      
                    return Json(Suggestion.InsertFail  + returnValue); //提示插入失败
                }
            }

            return Json(Suggestion.InsertFail + ",请核对输入的数据的格式"); //提示输入的数据的格式不对 
        }
 
//这是页面前端代码
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript">
        KindEditor.ready(function (K) {
            window.editor = K.create('#HIDGGNR', {
                cssPath: '../plugins/code/prettify.css',
                uploadJson: '../../Scripts/kindeditor-4.1.7/asp.net/upload_json.ashx',
                fileManagerJson: '../../Scripts/kindeditor-4.1.7/asp.net/file_manager_json.ashx',
                width: '500px'
            });
           });
        function nnn() {
            document.getElementById("HIDGGNR").value = editor.text();
        }
    </script>
    <fieldset>
        <legend>
            <input  class="a2 f2" type="submit" onclick="nnn()"  value="创建" />
            <input class="a2 f2" type="button" onclick="BackList('ZAJGGG')" value="返回" />
        </legend>
        <div class="bigdiv">
            <div class="editor-label">
                <%: Html.LabelFor(model => model.GGBT) %>:
            </div>
            <div class="editor-field">
                <%: Html.EditorFor(model => model.GGBT) %>
                <%: Html.ValidationMessageFor(model => model.GGBT) %>
            </div>
            <div class="editor-label">
                <a class="anUnderLine" onclick="showModalOnly('FCDWID','../../XQFWGL/IndexSearch');">
                    <%: Html.LabelFor(model => model.FCDWID) %>
                </a>:
            </div>
            <div class="editor-field">
                <div id="checkFCDWID">
                </div>
                <%: Html.HiddenFor(model => model.FCDWID)%>
            </div>
            <div class="editor-label">
                <%: Html.LabelFor(model => model.GGLB) %>:
            </div>
            <div class="editor-field">
                <%: Html.EditorFor(model => model.GGLB) %>
                <%: Html.ValidationMessageFor(model => model.GGLB) %>
            </div>
            <div class="editor-label">
            </div>
            <div class="editor-field">
                <input type="button" name="name" onclick="nnn()" value="点击 " />
            </div>
            <%-- 治安监管公告内容 --%>
            <div class="editor-label">
                <%: Html.LabelFor(model => model.GGNR) %>:
            </div>
            <br />
            <div class="editor-field" runat="server"> 
                <%:Html.TextAreaFor(model => model.HIDGGNR, new {width="700px",height= "500px"})%>
            </div> 
        </div>
    </fieldset>
</asp:Content>
 
 
//在另一个页面需要获取保存的html页面并显示出来html页面上的内容。(我应该怎么实现呢?)
发表新帖 发表回复