我查看了在 Razor Views 上可以找到的所有内容,但我找不到任何关于如何将此 UrlHelper 用法从 WebForms 转换为 Razor 的信息。
.ASPX 代码示例:
<img src="<%= Url.AccountPicture(Model.Picture, "bigger") %>" alt="<%= Html.AttributeEncode(Model.FullName) %>" width="73" height="73" />
我如何将其转换为 RAZOR:
<img src="@Url.AccountPicture(Model.Picture, "bigger")" alt="@Html.AttributeEncode(Model.FullName)" width="73" height="73" />
附带的 UrlHelperExtensions.cs 文件:
namespace ShadowVenue.Extensions
{
public static class UrlHelperExtensions
{
public static string AccountPicture(this UrlHelper helper, string name, string size)
{
if (string.IsNullOrEmpty(name))
name = "default";
return helper.Content(string.Format("~/content/images/pictures/{0}_{1}.png", name, size));
}
}
}
Visual Studio 突出显示的错误 |@Url。账户图片| 和:
“System.Web.Mvc.UrlHelper”不包含“AccountPicture”的定义,并且找不到接受“System.Web.Mvc.Helper”类型的第一个参数的扩展方法“AccountPicture”(您是否缺少 using 指令或装配参考?)
它在运行时产生此错误:
“System.Web.Mvc.UrlHelper”不包含“AccountPicture”的定义,并且找不到接受“System.Web.Mvc.UrlHelper”类型的第一个参数的扩展方法“AccountPicture”(您是否缺少 using 指令还是汇编参考?)
我在 web.config 中注册了命名空间 ShadowVenue.Extensions
请帮忙,谢谢!