I have tried to create HtmlHelper for MVC 5 app in F# my implementation is following:
namespace FSharpStore.WebUI.HtmlHelpers
module PagingHelpers =
type HtmlHelper with
static member PageLinks(info: PagingInfo, url : UrlHelper) : MvcHtmlString =
let pageUrl x = url.Action("List", x.ToString())
let sb = new StringBuilder()
for i in 0..info.TotalPages do
let tag = new TagBuilder("a")
tag.MergeAttribute("href", pageUrl(i))
tag.InnerHtml <- i.ToString()
if i = info.CurrentPage then
tag.AddCssClass("selected")
tag.AddCssClass("btn-primary")
tag.AddCssClass("btn btn-default")
sb.Append(tag.ToString()) |> ignore
MvcHtmlString.Create(sb.ToString())
and I have tried used it in view accordingly:
@using FSharpStore.WebUI.HtmlHelpers
<div class="btn-group pull-right">
@Html.PageLinks(Model.PagingInfo, this.Url)
</div>
Code is not compilable and it give me message : 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'PageLinks' and no extension method 'PageLinks' accepting a first argument of type 'System.Web.Mvc.HtmlHelper' could be found (are you missing a using directive or an assembly reference?)
Have anyone done HtmlHelper in F# successfully? I have tried used code extensions in difference part of project and they are just working. I think it's something special with razor itself.