I just upgraded to .NET8 so I dropped Newtonsoft.Json. Unfortunately, I have a problem with HTML serialisation. HtmlAttributeName don't take any effect.
Startup.cs
services.AddControllersWithViews();
services.AddMvc().AddControllersAsServices();
services.AddControllers().AddJsonOptions(options =>
{
options.JsonSerializerOptions.PropertyNamingPolicy = null;
});
Serialized class
public class ToolTip
{
[HtmlAttributeName("tooltipText")]
[JsonPropertyName("tooltipText")]
public string TooltipText { get; set; }
[HtmlAttributeName("template")]
[JsonPropertyName("template")]
public string Template { get; set; }
}
Output.cshtml
<div class="control-wrapper">
<div id="rteSection">
<ejs-richtexteditor id="@Model.Id" e="" actionBegin="handleFullScreen" enableHtmlSanitizer="false" created="created" quickToolbarOpen="quickToolbarOpenEvent" change="change" focus="focus" saveInterval="1000" height="500" format="@Model.Format" toolbarClick="toolbarClicked">
<e-richtexteditor-toolbarsettings items="@Model.Items"></e-richtexteditor-toolbarsettings>
<e-richtexteditor-quicktoolbarsettings link="@Model.QuickToolbarLinkItems"></e-richtexteditor-quicktoolbarsettings>
<e-richtexteditor-iframesettings enable="true"></e-richtexteditor-iframesettings>
<e-richtexteditor-pastecleanupsettings plainText="true" allowedStyleProps="null"></e-richtexteditor-pastecleanupsettings>
<e-content-template>
@Model.Value
</e-content-template>
</ejs-richtexteditor>
</div>
</div>
When I came back to Newtsoft.Json serialise it works.
services.AddControllers().AddNewtonsoftJson(options =>
{
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
});
Output is TooltipText and Template. What am I missing? Thanks for your help.