I tried to create this HtmlHelper method:
namespace Power.WebUx.Helpers
{
public static class HtmlHe开发者_JS百科lperExtensions
{
public static MvcHtmlString SelectedIfMatch(this HtmlHelper helper, string actual, string expected)
{
if (expected == actual)
{
return new MvcHtmlString("<option selected=\"selected\" value=\"" + actual + "\"" + actual + "</option>");
}
else
{
return new MvcHtmlString("<option value=\"" + actual + "\"" + actual + "</option>");
}
}
I added the Power.WebUx.Helpers line to my web.config:
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
<add namespace="Power.WebUx.Helpers" />
</namespaces>
</pages>
However when I try to use the extension I get an error message saying that System.Web.Mvc.HtmlHelper does not contain a definition for SelectedIfMatch
Does the code I am trying to run look right or am I missing something?
Hope someone can see something obvious.
thanks
Jon Wylie
Import the namespace into your view to use any extension methods in that namespace
<%@ Import Namespace = "Power.WebUx.Helpers" %>
Make sure you're modifying the top level web.config file(instead of the one in the views folder), then close and open the files where you're trying to use the helper
精彩评论