WYSIWYG文本编辑器SummerNote输入的数据不会持久存在

时间:2016-02-06 00:29:47

标签: asp.net entity-framework summernote

A picture of my problem

以上是我的编辑页面的图片。我遇到的问题是这个编辑器(summernote)在保存时不会保留它的数据

然而,我已经缩小了问题范围。 **

  • 表单上的字段会将数据保留在HTML元素的值字段中
  • SummerNote不会将我写入编辑器的文本存储在值元素
  • 如果我使用默认编辑器并输入一个值(存储在value元素中),则使用summernote,值字段中的值将存在,但不会显示。
  • 在检查器中编辑此值字段将导致该值在保存时保留。

包含值字段的行:



<input class="form-control text-box single-line" id="Content_Content" name="Content.Content" type="text" value="I am the text that is not shown but would be persisted!" style="display: none;">
&#13;
&#13;
&#13;

音符编辑区div:

&#13;
&#13;
<div class="note-editing-area"><div class="note-handle"><div class="note-control-selection" style="display: none;"><div class="note-control-selection-bg"></div><div class="note-control-holder note-control-nw"></div><div class="note-control-holder note-control-ne"></div><div class="note-control-holder note-control-sw"></div><div class="note-control-sizing note-control-se"></div><div class="note-control-selection-info"></div></div></div><textarea class="note-codable"></textarea><div class="note-editable panel-body" contenteditable="true" style="height: 320px;"><h1>Help!</h1><p>What I type here will not be persisted when i click the <b>save </b>button.</p></div></div>
&#13;
&#13;
&#13;

我的问题是:

我怎么能

  1. 将summernote编辑器的:: before和:: after之间的html(用户在控件中键入的值)放入值标记以及它是否持久化
  2. 做其他事情让它发挥作用。

    <小时/>

  3. 其他信息:

    这是我的模特:

    Article.cs:

    public class Article
    {
        #region Constructors
    
        public Article(string title, string subTitle = "")
        {
            InitializeCollections();
            Title = title;
            SubTitle = subTitle;
        }
        public Article(string title, Article parentArticle, string subTitle = "")
        {
            InitializeCollections();
            Title = title;
            SubTitle = subTitle;
            ParentArticles.Add(parentArticle);
        }
    
        public Article()
        {
            InitializeCollections();
        }
    
        void InitializeCollections()
        {
            ParentArticles = new List<Article>();
            ChildArticles = new List<Article>();
        }
    
        #endregion
    
        [Key]
        public int ArticleId { get; set; }
        public virtual ArticleContent Content { get; set; }
    
        [StringLength(GUIConstants.MaxCharactersInMenuItemText)]
        public string Title { get; set; }
        [StringLength(100)]
        public string SubTitle { get; set; }
        public int? Sequence { get; set; }
        public bool Published { get; set; }
        public DateTime? PublishedDate { get; set; }
        public virtual ICollection<Article> ParentArticles { get; set; }
        public virtual ICollection<Article> ChildArticles { get; set; }
        public string Notes { get; set; }
    

    文章内容(它是具有WYSIWYG编辑器的内容的内容属性,但是如果我在文章模型上直接使用WYSIWYG属性(如标题),我会遇到同样的问题。< / p>

        public class ArticleContent
    {
        [Key, ForeignKey("Article")]
        public int ArticleId { get; set; }
        public virtual Article Article { get; set; }
        [AllowHtml]
        public string Content { get; set; }
    }
    

    }

    控制器:

    // GET: Articles/Edit/5
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
    
            var article = db.Article.Include(a => a.Content).SingleOrDefault(a => a.ArticleId == id);
    
            if (article == null)
            {
                return HttpNotFound();
            }
    
            return View(article);
        }
    
        // POST: Articles/Edit/5
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [ValidateInput(false)]
        [HttpPost, ActionName("Edit")]
        public ActionResult EditPost(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
    
            var articleToUpdate = db.Article.Include(a => a.Content).SingleOrDefault(a => a.ArticleId == id);
    
            if (TryUpdateModel(articleToUpdate, "",
               new string[] { "Title", "SubTitle", "Sequence", "Content" }))
            {
                try
                {
                    db.SaveChanges();
    
                    return RedirectToAction("Index");
                }
                catch (RetryLimitExceededException /* dex */)
                {
                    //Log the error (uncomment dex variable name and add a line here to write a log.
                    ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
                }
            }
            return View(articleToUpdate);
        }
    

    查看:

        **@model Catalyst.Models.Article
    
    @{
        ViewBag.Title = "Edit Article";
    }
    
    @section styles{
        @Styles.Render("~/Content/summernote")
    }
    
    @using (Html.BeginForm())
    {
        @Html.AntiForgeryToken()
    
        <div class="form-horizontal">
            @Html.ValidationSummary(true, "", new { @class = "text-danger" })
            @Html.HiddenFor(model => model.ArticleId)
    
            <div class="form-group">
                @Html.LabelFor(model => model.Title, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Title, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Title, "", new { @class = "text-danger" })
                </div>
            </div>
    
            <div class="form-group">
                @Html.LabelFor(model => model.SubTitle, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.SubTitle, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.SubTitle, "", new { @class = "text-danger" })
                </div>
            </div>
    
            <div class="form-group">
                @Html.LabelFor(model => model.Sequence, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Sequence, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Sequence, "", new { @class = "text-danger" })
                </div>
            </div>
    
           <div class="form-group">
                @Html.LabelFor(model => model.Content.Content, htmlAttributes: new { @class = "control-label col-md-2" })
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Content.Content, new { htmlAttributes = new { @class = "form-control" } })
                    @Html.ValidationMessageFor(model => model.Content.Content, "", new { @class = "text-danger" })
                </div>
            </div>
    
            <div class="form-group">
                <div class="col-md-offset-2 col-md-10">
                    <input type="submit" value="Save" class="btn btn-default" />
                </div>
            </div>
        </div>
    }
    
    <div>
        @Html.ActionLink("Back to List", "Index", "Articles", new { @class = "btn btn-default" })
    </div>
    
    @section scripts {
       @Scripts.Render("~/bundles/SummerNote", "~/bundles/SummerNoteArticleContentEditor")
    }**
    

    Javascript将内容文本框转换为summernote

        (function ($) {  
        function HomeIndex() {  
            var $this = this;  
    
            function initialize() {  
                $('#Content_Content').summernote({
                    focus: true,  
                    height: 320,    
                    codemirror: {   
                        theme: 'united'  
                    }  
                });  
            }  
    
            $this.init = function () {  
                initialize();  
            }  
        }
        $(function () {  
            var self = new HomeIndex();  
            self.init();  
        })
    }(jQuery))
    

    我遵循了这个指南: http://www.c-sharpcorner.com/UploadFile/3d39b4/bootstrap-wysiwyg-editor-in-Asp-Net-mvc/

0 个答案:

没有答案