0

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!

Timothy Green
  • 1,851
  • 5
  • 17
  • 22
  • Would anyone know the awnser to this question also? [link]http://stackoverflow.com/questions/4975354/html-beginform-displaying-system-web-mvc-html-mvcform-on-page – Timothy Green Feb 12 '11 at 01:54
  • You should accept an answer by clicking the hollow check. – SLaks Feb 13 '11 at 00:34

2 Answers2

3

You need to include the ShadowVenue.Extensions namespace in the <system.web.webPages.razor> tag (not the <pages> tag).

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
1

In addition to SLaks' answer, you could put a @using ShadowVenue.Extensions tag at the top of your razor view for a one-off reference.

Eric King
  • 11,594
  • 5
  • 43
  • 53