我正在尝试对IIdentity使用扩展方法
这是我的班级:
public static class MyIdentity
{
public static string FullName(this IIdentity identity)
{
return "John Doe";
}
}我试着用它来表达我的观点:
@Context.User.Identity.FullName()但我得到了以下错误:
'System.Security.Principal.IIdentity‘不包含'FullName’的定义,也找不到接受'System.Security.Principal.IIdentity‘类型第一个参数的扩展方法'FullName’。
发布于 2012-08-23 16:10:40
请确保在视图中将定义此扩展方法的命名空间带入范围:
@using NameSpaceInWhichTheMyIdentityStaticClassIsDefined
@User.Identity.FullName()或者,如果要在许多视图中使用它以避免在每个视图中添加此命名空间,也可以将其添加到~/views/web.config的~/views/web.config部分(不要与~/web.config混淆):
<add namespace="NameSpaceInWhichTheMyIdentityStaticClassIsDefined" />https://stackoverflow.com/questions/12095876
复制相似问题