HtmlHelperExtensions are not visible in view mvc3 asp.net
- by user1299372
I've added a class for the HTML Custom Extensions:
using System;
using System.Linq.Expressions;
using System.Text;
using System.Web.Mvc;
using System.Web.Mvc.Html;
namespace App.MvcHtmlHelpers
{
public static class HtmlHelperExtensions
{
public static MvcHtmlString ComboBox(HtmlHelper html, string name, SelectList items, string selectedValue)
{
var sb = new StringBuilder();
sb.Append(html.DropDownList(name + "_hidden", items, new { @style = "width: 200px;", @onchange = "$('input#" + name + "').val($(this).val());" }));
sb.Append(html.TextBox(name, selectedValue, new { @style = "margin-left: -199px; width: 179px; height: 1.2em; border: 0;" }));
return MvcHtmlString.Create(sb.ToString());
}
public static MvcHtmlString ComboBoxFor<TModel, TProperty>(HtmlHelper<TModel> html, Expression<Func<TModel, TProperty>> expression, SelectList items)
{
var me = (MemberExpression)expression.Body;
var name = me.Member.Name;
var sb = new StringBuilder();
sb.Append(html.DropDownList(name + "_hidden", items, new { @style = "width: 200px;", @onchange = "$('input#" + name + "').val($(this).val());" }));
sb.Append(html.TextBoxFor(expression, new { @style = "margin-left: -199px; width: 179px; height: 1.2em; border: 0;" }));
return MvcHtmlString.Create(sb.ToString());
}
I've also registered it in my site web config:
<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="App.MvcHtmlHelpers"/>
</namespaces>
In my view, I import the namespace:
<%@ Import Namespace="RSPWebApp.MvcHtmlHelpers" %>
But when I go to call it in the view, it doesn't recognize the custom extension. Can someone help me by telling me what I might have missed? Thanks so much in advance!
<%:Html.ComboBoxFor(a => a.Street2, streetAddressListItems) %