在ASP.net MVC 5应用程序中,我正在使用Summernote.js来显示HTML文本编辑器,以便用户输入消息。我的模型包含必要的属性:
[AllowHtml]
[Display(Name = "Welcome Message")]
public string message { get; set; }
我的控制器将所有字段绑定到一个对象并将它们写入数据库:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "id,name,surveytype,industryId,start,end,message,resultsdate,resultsfile,resultsfile2")] Survey survey, HttpPostedFileBase bentemplate, HttpPostedFileBase comptemplate)
{
if (ModelState.IsValid)
{
if(bentemplate != null && bentemplate.ContentLength > 0)
{
var filename = Path.GetFileName(bentemplate.FileName);
var fullpath = Path.Combine(Server.MapPath("~/templates"), filename);
bentemplate.SaveAs(fullpath);
survey.bentemplateaddress = fullpath;
}
if (comptemplate != null && comptemplate.ContentLength > 0)
{
var filename = Path.GetFileName(comptemplate.FileName);
var fullpath = Path.Combine(Server.MapPath("~/templates"), filename);
bentemplate.SaveAs(fullpath);
survey.comptemplateaddress = fullpath;
}
db.surveys.Add(survey);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(survey);
}
相关的视图代码(textarea-editor类使它显示为Summernote编辑器):
@Html.LabelFor(model => model.message, htmlAttributes: new { @class = "control-label" })
@Html.EditorFor(model => model.message, new { htmlAttributes = new { @class = "form-control input-lg textarea-editor" } })
@Html.ValidationMessageFor(model => model.message, "", new { @class = "text-danger" })
不幸的是,除欢迎消息外,所有内容都在编写中。
关于造成这种情况的任何建议?
谢谢!