Saturday, 4 March 2017

MVC - Fix Error - The type or namespace name 'HtmlHelper' could not be found

Watch this example on YouTube




Error    CS0246    The type or namespace name 'HtmlHelper' could not be found (are you missing a using directive or an assembly reference?) 



To Fix it replace
namespace MVCIntranetTest.Controllers
{
    public static class MyBusiness
    {
      
        public static string GetUserRole(this HtmlHelper html)
        {
            CompanyEntities db = new CompanyEntities();
            string CurrentUser = HttpContext.Current.User.Identity.Name.ToString();
            CurrentUser = CurrentUser.ToLower().Replace("living\\", "");
            string Role = db.GetUserRole(CurrentUser).FirstOrDefault();

            return Role;
        }
    }
}

with

namespace System.Web.Mvc
{
    public static class MyBusiness
    {
      
        public static string GetUserRole(this HtmlHelper html)
        {
            CompanyEntities db = new CompanyEntities();
            string CurrentUser = HttpContext.Current.User.Identity.Name.ToString();
            CurrentUser = CurrentUser.ToLower().Replace("living\\", "");
            string Role = db.GetUserRole(CurrentUser).FirstOrDefault();

            return Role;
        }
    }
}

No comments:

Post a Comment