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;

4 Answers 4

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>
Sign up to request clarification or add additional context in comments.

Comments

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>

Comments

2

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

// system.web / compilation / assemblies
<add assembly="Microsoft.Web.Mvc"/>

Comments

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()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.