Testing HtmlHelpers in LinqPad

chuckles
edited June 2012 in Root
I would like to be able to use LinqPad as a test bed for HtmlHelpers. Any help would be appreciated.

Here's what I have so far...

References
System.Web.dll
System.Web.Mvc.dll
System.Web.Routing.dll

Namespace Imports
System.Web.Mvc

var viewContext = new ViewContext(); var viewDataContainer = (IViewDataContainer) new object(); var html = new HtmlHelper(viewContext, viewDataContainer); html.ActionLink("Test", "Test", "Test").Dump();

It fails when I attempt to cast an object to IViewDataContainer.

Thanks

Comments

  • The line:

    var viewDataContainer = (IViewDataContainer) new object();

    is invalid. The object class does not implement IViewDataContainer, so the conversion will fail.
  • Yeah, but how can I get around that easily? Anyone have any ideas?
  • Does someone can give an answer for this interesting question ?
  • What are you trying to do?
  • It will be very interesting to test HTMLHelpers in MVC world.
    For example able to test something like this :

    public static string ValidationImage(this HtmlHelper helper, string name)
    {
    if ((helper.ViewData.ModelState[name] == null) ||
    (helper.ViewData.ModelState[name].Errors == null) ||
    (helper.ViewData.ModelState[name].Errors.Count == 0))
    return String.Empty;

    var tag = GenerateTagImage(helper, helper.ViewData.ModelState[name].Errors[0].ErrorMessage);

    var tagSpan = new TagBuilder("span");
    tagSpan.AddCssClass("pictoError");
    tagSpan.InnerHtml = tag.ToString(TagRenderMode.SelfClosing);

    return tagSpan.ToString(TagRenderMode.Normal);
    }