2

I want to include some namespaces with their classes in my asp.net application. It is possible with using keyword ?

I have this:

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <%
       SomeNamespace.Models.NewsModel getNewsDetail = ViewData["NewsDetail"] as SomeNamespace.Models.NewsModel;

       if ( getNewsDetail != null ) {
            %>
            <h2>'<%= getNewsDetail.NewsTitle%>' details</h2>
            <div class="discipline-details">
            <ul>
            <li>
            <h3> <%= getNewsDetail.NewsTitle%></h3>            
            <p><%= getNewsDetail.NewsDescription%></p>
            </li>
            </ul>
            </div>
    <%
          } else {
         %> <p class="error">No news is available. Below is listed the available news.</p>
         <div id="home-news">

        </div>
          <%
          }
     %>

</asp:Content>

I used MVC2 architecture ...

I want to use directly the class NewsModel getNewsDetail = ViewData["NewsDetail"] as NewsModel.

Thank you and sorry if my question is poor.

Snake Eyes
  • 16,287
  • 34
  • 113
  • 221

4 Answers4

3

Use Import at the top of the view:

<%@ Import Namespace="SomeNamespace" %>
Samich
  • 29,157
  • 6
  • 68
  • 77
1

You can add

<%@ Import Namespace="The.Namespace" %>

at the top of the view but there seems to be something wrong with the original idea. You should probably use strongly typed view.

Stilgar
  • 22,354
  • 14
  • 64
  • 101
1

you can do this:

<%@ Import Namespace="MyNamespace" %>
lnu
  • 1,404
  • 1
  • 9
  • 25
1

According to your code block, Would you please try below: (write this code at the top of the page, page Page directive )

<%@ Import Namespace="SomeNamespace.Models" %>
Elias Hossain
  • 4,410
  • 1
  • 19
  • 33