我有一个奇怪的情况,我们有这个视图模型:
public class AddCommunicationViewModel
{
public Guid Id { get; set; }
public Guid ParentCommunicationGroupId { get; set; }
public Guid ParentCommunicationGroupCampaignId { get; set; }
public List<SelectListItem> CommunicationTypes { get; set; }
public CommunicationType SelectedCommunicationTypeId { get; set; }
[AllowHtml]
public string Subject { get; set; }
[AllowHtml]
public string Content { get; set; }
public string Reference { get; set; }
public bool AttachDemand { get; set; }
public int CommunicationSortingIndex { get; set; }
public string CommunicationGroupName { get; set; }
public AddCommunicationViewModel()
{
CommunicationTypes = new List<SelectListItem>();
}
}
现在,我有一个非常简单的表单(使用Html.BeginForm
),它会发布到控制器:
@using (Html.BeginForm("UpdateSavedCommunication", "Communication", FormMethod.Post, new { id = "saveCommunication" }))
{
@Html.HiddenFor(c => c.ParentCommunicationGroupCampaignId)
@Html.HiddenFor(c => c.ParentCommunicationGroupId)
@Html.HiddenFor(c => c.Id)
<div class="form-group">
@Html.LabelFor(c => c.SelectedCommunicationTypeId)
@Html.DropDownListFor(c => c.SelectedCommunicationTypeId, Model.CommunicationTypes, new { @class = "form-control" })
</div>
<div class="div_subject form-group email">
@Html.LabelFor(c => c.Subject)
@Html.TextBoxFor(c => c.Subject, new { @class = "form-control" })
</div>
<div class="div_content form-group mb-3">
@Html.LabelFor(c => c.Content)
<div class="card-body">
<form class="form-horizontal form-bordered">
<div class="form-group row">
<div class="col-sm-12">
<textarea name="Content" id="summernote" class="summernote" data-plugin-summernote data-plugin-options='{ "height": 280, "codemirror": { "theme": "ambiance" } }'>
@Html.Raw(Model.Content)
</textarea>
</div>
</div>
</form>
</div>
</div>
<div class="div_reference form-group email">
@Html.LabelFor(c => c.Reference)
@Html.TextBoxFor(c => c.Reference, new { @class = "form-control" })
</div>
<div class="div_attachdemand form-group mb-3">
<div>
@Html.LabelFor(c => c.AttachDemand)
@Html.CheckBoxFor(c => c.AttachDemand)
</div>
</div>
<input type="submit" class="btn btn-success" value="Gem" onclick="document.getElementById('saveCommunication').submit();" />
}
我&#34; Content&#34;变量有点奇怪,是因为我使用了Summernote编辑器。当我点击提交按钮时,所有帖子都没有任何JavaScript错误。
然而,现在出现了奇怪的东西。
我的变量:Reference
和AttachDemand
未发布到服务器。看着提琴手,我可以看到这是帖子:
ParentCommunicationGroupCampaignId=00000000-0000-0000-0000-000000000000&ParentCommunicationGroupId=00000000-0000-0000-0000-000000000000&Id=2953bc1b-49e5-4f65-8159-1c53de5c82e8&SelectedCommunicationTypeId=2&Subject=&Content=++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%3Cp%3E%3Cspan+style%3D%22color%3A+rgb%280%2C+0%2C+0%29%3B%22%3EHej%C2%A0*%7CNAME%7C*.%C2%A0%3C%2Fspan%3E%3C%2Fp%3E%3Cp%3E%3Cspan+style%3D%22color%3A+rgb%280%2C+0%2C+0%29%3B%22%3E*%7CCREDITORNAME%7C*+har+bedt+os+inddrive+din+g%C3%A6ld+hos+dem.+Der+er+tale+om+en+g%C3%A6ld+p%C3%A5%3C%2Fspan%3E%3Cspan+style%3D%22color%3A+rgb%280%2C+0%2C+0%29%3B%22%3E%C2%A0%3C%2Fspan%3E%3Cspan+style%3D%22color%3A+rgb%280%2C+0%2C+0%29%3B%22%3E*%7CDEMANDLINK%7C*+kr%2C+som+du+bedes+betale.%3Cbr%3EVi+har+vedh%C3%A6ftet+kravet+i+dette+brev+p%C3%A5+e-mail.%3C%2Fspan%3E%3C%2Fp%3E%3Cp%3E%3Cspan+style%3D%22color%3A+rgb%280%2C+0%2C+0%29%3B%22%3EDet+er+vigtigt+at+du+betales+denne+g%C3%A6ld+hurtigst+muligt%2C+for+at+undg%C3%A5+at+der+p%C3%A5l%C3%B8ber+ekstra+renter+samt+en+registrering+hos+RKI+og+som+videre+konsekvens+sendt+til+fogedretten.%3C%2Fspan%3E%3C%2Fp%3E%3Cp%3E%3Cspan+style%3D%22color%3A+rgb%280%2C+0%2C+0%29%3B%22%3ESE+DIN+SAG+OG+BETAL%3A+*%7CDEMANDLINK%7C*%C2%A0%3C%2Fspan%3E%3C%2Fp%3E%3Cp%3E%3Cspan+style%3D%22color%3A+rgb%280%2C+0%2C+0%29%3B%22%3E%3Cbr%3E%3C%2Fspan%3E%3C%2Fp%3E%3Cp%3E%3Cspan+style%3D%22color%3A+rgb%280%2C+0%2C+0%29%3B%22%3EVh%3Cbr%3E%3C%2Fspan%3E%3C%2Fp%3E%0D%0A++++++++++++++++++++++++%0D%0A++++++++++++++++++++++++%0D%0A++++++++++++++++++++++++%0D%0A++++++++++++++++++++++++%0D%0A++++++++++++++++++++++++&files=
或者在人类看来:
所以我的挑战是:Reference
和AttachDemand
?
现在,如果我将这两个移动到内容编辑器上,它们就可以了。所以似乎Content
正在破坏,因为它发送了一些非常酷的HTML。
所以任何想法如何制作&#34;这项工作?我想我需要以某种聪明的方式以某种方式逃避输入?我在内容属性上添加了[AllowHtml]
,因为它将包含HTML,但不仅仅包含HTML?
答案 0 :(得分:2)
您的视图具有嵌套的表单,这些表单是无效的HTML并且不受支持(根据浏览器和版本,您可能会看到不同的结果)。
删除textarea周围的内部<form class="form-horizontal form-bordered">
,以确保序列化所有from控件并在请求中发送。