I looked through everything I could find on Razor Views, but I could not find anything on how to convert this UrlHelper usage to Razor from WebForms.
.ASPX Code Sample:
<img src="<%= Url.AccountPicture(Model.Picture, "bigger") %>" alt="<%= Html.AttributeEncode(Model.FullName) %>" width="73" height="73" />
How I converted it to RAZOR:
<img src="@Url.AccountPicture(Model.Picture, "bigger")" alt="@Html.AttributeEncode(Model.FullName)" width="73" height="73" />
The UrlHelperExtensions.cs File that goes with it:
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));
}
}
}
Error That Visual Studio Highlights |@Url.AccountPicture| with:
'System.Web.Mvc.UrlHelper' does not contain a definition for 'AccountPicture' and no extension method 'AccountPicture' accepting a first argument of type 'System.Web.Mvc.Helper' could be found (are you missing a using directive or assembly reference?)
It Produces This Error on RunTime:
'System.Web.Mvc.UrlHelper' does not contain a definition for 'AccountPicture' and no extension method 'AccountPicture' accepting a first argument of type 'System.Web.Mvc.UrlHelper' could be found (are you missing a using directive or an assembly reference?)
I have namespace ShadowVenue.Extensions registed in the web.config
Please Help, Thank You!