MVC4HTML永远不会在POST上解码

MVC4HTML永远不会在POST上解码,html,asp.net-mvc,post,decoding,Html,Asp.net Mvc,Post,Decoding,我使用剑道编辑器来创建电子邮件模板,在帖子中,一旦提交了对模板的更改,总是以编码HTML呈现 这是我在页面上的razor代码: @model Business.Models.Administration.EmailSetupViewModel @using Kendo.Mvc.UI; <h2>Application Stages Portal</h2> <h4>Email Setup</h4> @using (Html.BeginForm()

我使用剑道编辑器来创建电子邮件模板,在帖子中,一旦提交了对模板的更改,总是以编码HTML呈现

这是我在页面上的razor代码:

@model Business.Models.Administration.EmailSetupViewModel
@using Kendo.Mvc.UI;

<h2>Application Stages Portal</h2>

<h4>Email Setup</h4>

@using (Html.BeginForm())
{

    if (Model.EmailSaved)
    {
        <h2>
            Email template saved</h2>
    }
    else
    {
       @* @Html.DisplayFor(m => m.EmailSavedMsg)*@
    }

    @Html.DropDownListFor(m => m.EmailTemplateToEdit, Model.EmailTemplatesList)
    <input type="submit" name="setup" value="setup" />

    if (Model.ShowEmailForm)
    {
    <div id="email-edit">
        @Html.Label("Title")
        @Html.TextBoxFor(m => m.EmailTitle, new { style = "width:200px" })
        <br />

        @(Html.Kendo().Editor()
      .Name("editor")
      .HtmlAttributes(new { style = "width: 600px;height:440px" })
      .Value(@<text>
        @Html.Raw(Model.EmailBody)
        </text>))
    </div>

    <input type="submit" id="btnSaveTemplate" name="update" value="update" />

    <h2>
        Please note</h2>
    <p>
        The following items are <i>reserved and should not be changed, you may move them
            to a different place within the message. </i>

        <ul>
            <li><*name*> e.g. Fred Flinstone </li>
            <li><*membernumber*> e.g. 12345678 </li>
        </ul>
    </p>
    }
} 
这是我的模型,我正在属性上使用[AllowHtml]属性

使用制度; 使用System.Collections.Generic; 使用System.Linq; 使用系统文本; 使用System.Web.Mvc

namespace Business.Models.Administration
{
    public class EmailSetupViewModel
    {
        public EmailSetupViewModel()
        {
            this.EmailTemplatesList = new List<SelectListItem>();
        }

        public string EmailTemplateToEdit { get; set; }
        public List<SelectListItem> EmailTemplatesList { get; set; }
        public string EmailTitle { get; set; }
        [AllowHtml]
        public string EmailBody { get; set; }
        public bool ShowEmailForm { get; set; }

        public bool EmailSaved { get; set; }
        public string EmailSavedMsg { get; set; }
    }
}
namespace Business.Models.Administration
{
公共类EmailSetupViewModel
{
公共EmailSetupViewModel()
{
this.EmailTemplatesList=新列表();
}
公共字符串EmailTemplateToEdit{get;set;}
公共列表EmailTemplatesList{get;set;}
公共字符串EmailTitle{get;set;}
[allowtml]
公共字符串EmailBody{get;set;}
公共bool showmailform{get;set;}
公共bool EmailSaved{get;set;}
公共字符串EmailSavedMsg{get;set;}
}
}
最后是两个截图,一个在GET上,一个在POST上

我也在使用ModelState.Clear(),但当我再次单击浏览器时,它无法解码


因此,基本上我需要帮助在我的编辑器中在post上呈现HTML,以便它正确呈现,并且不会在编辑器中显示HTML标记。

有人知道如何解决此问题吗?我建议在提交后在编辑器中获取HTMLL并使用decodeURIComponent(HTML);。获取decodeURIComponent的结果并设置编辑器值。
#region Email template
        [HttpGet]
        public ActionResult EmailSetup()
        {
            ViewBag.DisplayName = StaticFunctions.GetDisplayName(this.User.Identity.Name);
            EmailSetupViewModel model = new EmailSetupViewModel();
            Business.Administration.Email Email = new Business.Administration.Email();
            var list = Email.GetTemplateList();
            model.EmailTemplatesList = list.OrderBy(o => o.Text).ToList();
            return View(model);
        }

        [HttpPost]
        public ActionResult EmailSetup(EmailSetupViewModel model, string value, string editor)
        {
            ViewBag.DisplayName = StaticFunctions.GetDisplayName(this.User.Identity.Name);
            string body = HttpUtility.HtmlDecode(editor); //encode to db

            if (Request["update"] != null)
            {
                Business.Administration.Email Email = new Business.Administration.Email();
                model.EmailSaved = Email.SaveTemplate(model, body);
                //ModelState.Clear(); // when doing POST - clearing the ModelState will prevent encode of HTML (Default behaviour). This isn't good long term solution.

                if (model.EmailSaved)
                {
                    model.EmailSavedMsg = "Template saved";
                }
                else
                {
                    model.EmailSavedMsg = "Template couldn't be saved";
                }

                model.EmailTemplatesList = Email.GetTemplateList();
                model = Email.GetTemplate(model);
                model.EmailBody = HttpUtility.HtmlDecode(model.EmailBody);
                return View(model);
            }
            else
            {
                Business.Administration.Email Email = new Business.Administration.Email();
                model.EmailTemplatesList = Email.GetTemplateList();
                model = Email.GetTemplate(model);
                model.EmailBody = HttpUtility.HtmlDecode(model.EmailBody);
                return View(model);
            }
        }
        #endregion
namespace Business.Models.Administration
{
    public class EmailSetupViewModel
    {
        public EmailSetupViewModel()
        {
            this.EmailTemplatesList = new List<SelectListItem>();
        }

        public string EmailTemplateToEdit { get; set; }
        public List<SelectListItem> EmailTemplatesList { get; set; }
        public string EmailTitle { get; set; }
        [AllowHtml]
        public string EmailBody { get; set; }
        public bool ShowEmailForm { get; set; }

        public bool EmailSaved { get; set; }
        public string EmailSavedMsg { get; set; }
    }
}