15

I place using namespace in a view code behind but i can't call any class of this name space in aspx.

In codebehind:

using MVCTest.Controller;
James Wiseman
  • 29,946
  • 17
  • 95
  • 158
StoneHeart
  • 15,790
  • 32
  • 67
  • 84

4 Answers4

31

try to use in your aspx / ascx file

<%@ import namespace='your namespace' %>

you could also try to import your namespace in the web.config

<system.web>
  <pages>
    <namespaces>
      <add namespace='you namespace' />
    </namespaces>
  </pages>
</system.web>
Mark
  • 11,257
  • 11
  • 61
  • 97
JSC
  • 3,705
  • 3
  • 26
  • 25
10

Add the import statement If you are using the ASP.NET (C#) engine:

<%@ Import Namespace="My.Namespace.Path" %>

<html goes here>
    ...
</html>

OR

Add the using statement to your view if you are using the Razor engine:

@using My.Namespace.Path

@{
    ViewBag.Title = "My Page";
    ...
}

<html goes here>
   ...
</html goes here>
undeniablyrob
  • 1,339
  • 2
  • 16
  • 16
2

Did you remember to include the assembly as well? E.g. like this:

// system.web / compilation / assemblies
<add assembly="Microsoft.Web.Mvc"/>
mookid8000
  • 18,258
  • 2
  • 39
  • 63
0

Suppose this is your .Cs file say

namespace MVCTest.Controller {

public class Utility

{ 
   public static void func1()
   {} 
}

}

Try calling the function by : Utility.func1()

Samiksha
  • 6,122
  • 6
  • 29
  • 28