You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
iot/projects/Infrastructure/Extensions/HtmlHelperExtensions.cs

31 lines
939 B

using System;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.Routing;
namespace Infrastructure.Extensions
{
public static class HtmlHelperExtensions
{
public static IUrlHelper GetUrlHelper(this IHtmlHelper helper)
{
return new UrlHelperFactory().GetUrlHelper(helper.ViewContext);
}
public static void Set(this IHtmlHelper helper, string key, string value)
{
helper.ViewContext.HttpContext.Items.Add(key, value);
}
public static IHtmlContent Get(this IHtmlHelper helper, string key)
{
if (helper.ViewContext.HttpContext.Items.TryGetValue(key, out object value))
{
return new HtmlString(value as string);
}
return HtmlString.Empty;
}
}
}