using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MyHelpers;
namespace FluentHtmlHelpers.Models
{
public class SampleAlertModel
{
public string AlertBoxText { get; set; }
public MyHelpers.AlertStyle AlertBoxStyle { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
namespace MyHelpers
{
///
/// Generates an Alert message
///
public static class AlertHtmlHelper
{
///
/// Generates an Alert message
///
public static AlertBox Alert(this IHtmlHelper html,
string text,
AlertStyle alertStyle = AlertStyle.Default,
bool hideCloseButton = false,
object htmlAttributes = null)
{
return new AlertBox(text, alertStyle, hideCloseButton, htmlAttributes);
}
// Strongly typed
///
/// Generates an Alert message
///
public static AlertBox AlertFor(this IHtmlHelper html,
Expression expression,
AlertStyle alertStyle = AlertStyle.Default,
bool hideCloseButton = false,
object htmlAttributes = null)
{
var metadata = ExpressionMetadataProvider.FromLambdaExpression(expression, html.ViewData, html.MetadataProvider);
return new AlertBox((string)metadata.Model, alertStyle, hideCloseButton, htmlAttributes);
}
///
/// Generates an Alert message
///
public static AlertBox AlertFor(this IHtmlHelper html,
Expression textExpression,
Expression styleExpression,
bool hideCloseButton = false,
object htmlAttributes = null)
{
var text = (string) ExpressionMetadataProvider.FromLambdaExpression(textExpression, html.ViewData, html.MetadataProvider).Model;
var alertStyle = (AlertStyle)ExpressionMetadataProvider.FromLambdaExpression(styleExpression, html.ViewData, html.MetadataProvider).Model;
return new AlertBox(text, alertStyle,hideCloseButton, htmlAttributes);
}
}
}
Но я получаю эту ошибку:
TypeLoadException: не удалось загрузить тип «Microsoft.AspNetCore.Mvc.ViewFeatures. Internal.ExpressionMetadataProvider» из сборки «Microsoft.AspNetCore.Mvc.ViewFeatures, версия = 8.0.0.0, культура = нейтральная, PublicKeyToken=adb9793829ddae60'.
Html.AlertFor(m => m.AlertBoxText, m => m.AlertBoxStyle) @Html.AlertFor(m => m.AlertBoxText, m => m.AlertBoxStyle) [/code] SampleAlertModel: [code] using System; using System.Collections.Generic; using System.Linq; using System.Web; using MyHelpers;
namespace FluentHtmlHelpers.Models { public class SampleAlertModel { public string AlertBoxText { get; set; } public MyHelpers.AlertStyle AlertBoxStyle { get; set; } } } [/code] >AlertHtmlHelper: [code] using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Html; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding; using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
namespace MyHelpers { /// /// Generates an Alert message /// public static class AlertHtmlHelper { /// /// Generates an Alert message /// public static AlertBox Alert(this IHtmlHelper html, string text, AlertStyle alertStyle = AlertStyle.Default, bool hideCloseButton = false, object htmlAttributes = null) { return new AlertBox(text, alertStyle, hideCloseButton, htmlAttributes); }
/// /// Generates an Alert message /// public static AlertBox AlertFor(this IHtmlHelper html, Expression textExpression, Expression styleExpression, bool hideCloseButton = false, object htmlAttributes = null) { var text = (string) ExpressionMetadataProvider.FromLambdaExpression(textExpression, html.ViewData, html.MetadataProvider).Model; var alertStyle = (AlertStyle)ExpressionMetadataProvider.FromLambdaExpression(styleExpression, html.ViewData, html.MetadataProvider).Model;
return new AlertBox(text, alertStyle,hideCloseButton, htmlAttributes); }
} }
[/code] Но я получаю эту ошибку:
TypeLoadException: не удалось загрузить тип «Microsoft.AspNetCore.Mvc.ViewFeatures. Internal.ExpressionMetadataProvider» из сборки «Microsoft.AspNetCore.Mvc.ViewFeatures, версия = 8.0.0.0, культура = нейтральная, PublicKeyToken=adb9793829ddae60'.