How to use Helpers and Extensions

Topics: Writing modules
Nov 7, 2013 at 4:37 PM
I have a few helpers from the past and i would like to use them on Orchard modul(widget, Views/Parts/someview.cshtml). Orchard dont see this. Maybe its problem in namespace registration. I register this as clasic MVC on web.config where views are.

Helper for example like this:
public static MvcHtmlString Image(this HtmlHelper html, string url, string alt, object htmlAttributes)
        {
            var imgBuilder = new TagBuilder("img");
            imgBuilder.MergeAttribute("src", url);
            imgBuilder.MergeAttribute("alt", alt);
            imgBuilder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
            string imgHtml = imgBuilder.ToString(TagRenderMode.SelfClosing);

            return MvcHtmlString.Create(imgHtml);
        }
Use like this:
@Html.Image(item.URL, item.Name, new { @title = @item.Description })
Coordinator
Nov 11, 2013 at 8:00 AM
Edited Nov 11, 2013 at 8:00 AM
All you have to do to use an extension method (and this is not specific to Orchard), is to add a using statement pointing at its namespace.
Nov 12, 2013 at 3:12 PM
Arror appeared because the orchard uses shame, I was used to model from classical MVC. Compiller did not know the data types of item.