【问题标题】:jEditable TextArea, I need to maintain formatting on save but show user friendly text on edit (MVC3)jEditable TextArea,我需要在保存时保持格式,但在编辑时显示用户友好的文本(MVC3)
【发布时间】:2012-10-02 16:42:07
【问题描述】:

我在我的程序的文本区域中使用 jEditable 插件。我想做的是当我单击文本区域时,我想输入如下内容: 先做这个 做到这一点 做第三个。

当我提交时,我希望 jEditable 保留我现有的格式,这是我当前的 textarea 所做的,但是当我单击 textarea 再次编辑时,它会显示以下内容: 先做这个
做第二个
做第三个。

我希望能够再次单击文本区域进行编辑,然后让它显示用户友好的文本,而不是它所做的 html,但我需要保持格式不变。

下面是我的 javascript、视图和控制器。任何帮助都会很棒!

Javascript:

$(".textarea").editable("/ShoppingList/UpdateNotesReminders",
{
     type      : 'textarea',
     rows      : 7,
     columns   : 15,
     cancel    : 'Cancel',
     submit    : 'Save',
     method: 'POST',
     placeholder     : 'No Notes have been entered',
     callback: function(value, settings) { 
    var retval = value.replace(/\n/gi, "<br>"); 
    $(this).html(retval);
}
});

行动:

//This action is called when save button is clicked after editing notes and reminders.
        [ValidateInput(false)]
        public string UpdateNotesReminders(string id, string value)
        {
            HttpCookie notesRemindersCookie = new HttpCookie("notesRemindersCookie");
            notesRemindersCookie.Value = value.Replace("<br>", "%0a");
            notesRemindersCookie.Expires = DateTime.Now.AddDays(1);

            this.ControllerContext.HttpContext.Response.Cookies.Add(notesRemindersCookie);
            return value;
        }

查看:

<div class="textarea dynform" id="NotesReminders">@Html.Raw(Model.NotesReminders)</div> 

【问题讨论】:

    标签: html asp.net-mvc-3 razor view jeditable


    【解决方案1】:

    我认为您的帖子已从您尝试显示的一些 HTML 中删除...

    但我认为解决您的问题的方法是 HTMLEncode/Decode the user content.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-21
      • 2022-11-19
      • 1970-01-01
      相关资源
      最近更新 更多