StoneHeart
StoneHeart

Reputation: 16610

asp.net mvc - Namespace in view

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;

Upvotes: 15

Views: 19775

Answers (4)

undeniablyrob
undeniablyrob

Reputation: 1459

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>

Upvotes: 10

JSC
JSC

Reputation: 3725

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>

Upvotes: 31

Samiksha
Samiksha

Reputation: 6192

Suppose this is your .Cs file say

namespace MVCTest.Controller {

public class Utility

{ 
   public static void func1()
   {} 
}

}

Try calling the function by : Utility.func1()

Upvotes: 0

mookid8000
mookid8000

Reputation: 18628

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

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

Upvotes: 2

Related Questions