Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net mvc - Namespace in view

Tags:

asp.net-mvc

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;
like image 807
StoneHeart Avatar asked Dec 09 '08 08:12

StoneHeart


People also ask

How do you add a namespace in Razor view?

There are two ways to add namespaces: Put @using namespace at the top of the page. Put all the namespaces in Views\Web. config.

What is namespace of ASP NET MVC?

Mvc namespace contains classes and interfaces that support the ASP.NET Model View Controller (MVC) framework for creating Web applications. This namespace includes classes that represent controllers, controller factories, action results, views, partial view, model binders, and much more. The System. Web.

Which namespace is used by Razor?

The namespace for Razor Engine is System.


2 Answers

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>
like image 184
JSC Avatar answered Sep 29 '22 12:09

JSC


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>
like image 44
undeniablyrob Avatar answered Sep 29 '22 11:09

undeniablyrob