Testing HtmlHelpers in LinqPad
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
It fails when I attempt to cast an object to IViewDataContainer.
Thanks
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
var viewDataContainer = (IViewDataContainer) new object();
is invalid. The object class does not implement IViewDataContainer, so the conversion will fail.
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);
}