Der Typ konnte bei Verwendung von Microsoft.AspNetCore.Mvc.ViewFeatures nicht geladen werden
Posted: 05 Jan 2025, 13:33
Ich habe diesen HTML-Code auf der Seite:
SampleAlertModel:
>AlertHtmlHelper:
Aber ich erhalte diese Fehlermeldung:
TypeLoadException: Der Typ „Microsoft.AspNetCore.Mvc.ViewFeatures“ konnte nicht geladen werden. Internal.ExpressionMetadataProvider' aus Assembly 'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
Code: Select all
@using MyHelpers
@model FluentHtmlHelpers.Models.SampleAlertModel
@{
ViewBag.Title = "Strongly Typed";
}
Strongly Typed
Html.AlertFor(m => m.AlertBoxText).Success()
@Html.AlertFor(m => m.AlertBoxText).Success()
Html.AlertFor(m => m.AlertBoxText, m => m.AlertBoxStyle)
@Html.AlertFor(m => m.AlertBoxText, m => m.AlertBoxStyle)
Code: Select all
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: Select all
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: Der Typ „Microsoft.AspNetCore.Mvc.ViewFeatures“ konnte nicht geladen werden. Internal.ExpressionMetadataProvider' aus Assembly 'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.