命名空间
在net mvc中引用的 System.Web.Mvc
在net core mvc中引用 Microsoft.AspNetCore.Mvc.ViewFeatures
net mvc :
using System.Web.Mvc;
namespace System.Web.Mvc
{
public static class MyHelpers
{
public static MvcHtmlString Test(this HtmlHelper helper, string codename)
{
switch (codename.ToLower())
{
case "a":
return MvcHtmlString.Create(@"<span class='curentrpath'>" + A + "</span>");
default:
return MvcHtmlString.Create(@"<span class='curentrpath'>" + B + "</span>");
}
}
}
}
net core mvc:
using MBS.Resources;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
namespace Microsoft.AspNetCore.Mvc.ViewFeatures
{
public static class MyHelpers
{
public static Microsoft.AspNetCore.Html.HtmlString Test(string codename)
{
string result;
switch (codename.ToLower())
{
case "a":
TagBuilder model= new TagBuilder(@"<span class='curentrpath'>" + A + " </span>");
using (var sw = new System.IO.StringWriter())
{
model.WriteTo(sw, System.Text.Encodings.Web.HtmlEncoder.Default);
result = sw.ToString();
}
return new Html.HtmlString(result);
default:
TagBuilder tag= new TagBuilder(@"<span class='curentrpath'>" + B + "</span>");
using (var sw = new System.IO.StringWriter())
{
tag.WriteTo(sw, System.Text.Encodings.Web.HtmlEncoder.Default);
result = sw.ToString();
}
return new Html.HtmlString(result);
}
}
}
}