Reputation: 1182
I have implemented the project of migrating Asp.Net MVC into Asp.Net Core 3.1.
HomeController.cs
static Regex regex = new Regex("(</?)script", RegexOptions.IgnoreCase);
public static MvcHtmlString EmbeddedTemplate(EntityBase entityBase, MvcHtmlString template, string defaultString)
{
return MvcHtmlString.Create("<script type=\"template\" id=\"{0}\" data-toString=\"{2}\">{1}</script>"
.Formato(entityBase.Compose(EntityBaseKeys.Template),
regex.Replace(template.ToHtmlString(), m => m.Value + "X"),
defaultString));
}
I have followed the link: .NET CORE MvcHtmlString(TextboxFor, LabelFor).ToString() Error. Here it is suggested to use IHtmlContent(Interface). But it does not have a Create() method.
And also what is the equivalent of MvcHtmlString? Kindly suggest on alternative solution on this.
Upvotes: 2
Views: 2907
Reputation: 1182
Finally I got it. Asp.Net Core replaced MvcHtmlString for a new HtmlString type.
static Regex regex = new Regex("(</?)script", RegexOptions.IgnoreCase);
public static HtmlString EmbeddedTemplate(EntityBase entityBase, MvcHtmlString template, string defaultString)
{
return new HtmlString("<script type=\"template\" id=\"{0}\" data-toString=\"{2}\">{1}</script>"
.Formato(entityBase.Compose(EntityBaseKeys.Template),
regex.Replace(template.ToHtmlString(), m => m.Value + "X"),
defaultString));
}
Additionally, you need to declare the using directive
using Microsoft.AspNetCore.Html;
Upvotes: 4