检查项目中是否使用了自定义的标签扩展方法,如果有,需要确认方法中的参数名是否与标签中使用的属性名相同。以下是一个示例:
在标签中添加属性:
在扩展方法中处理标签:
public static IHtmlContent MyCustomTag(this IHtmlHelper helper, string myAttr) { // do something with myAttr return new HtmlString("
"); }在这个示例中,可以看到标签中使用了属性myAttr,但扩展方法的参数名为myAttr,并没有使用“@”符号来指示这是一个属性名。这会导致运行时出现奇怪的属性。解决方法是将扩展方法中的参数名改为“@myAttr”,以指示这是一个属性名:
public static IHtmlContent MyCustomTag(this IHtmlHelper helper, string @myAttr) { // do something with myAttr return new HtmlString("
"); }使用“@”符号来指示属性名是一种好习惯,可以避免在运行时出现奇怪的属性。