How do I import a namespace in Razor View Page?

后端 未结 11 1385
迷失自我
迷失自我 2020-11-22 11:03

How to import a namespace in Razor View Page?

相关标签:
11条回答
  • 2020-11-22 11:45

    "using MyNamespace" works in MVC3 RTM. Hope this helps.

    0 讨论(0)
  • 2020-11-22 11:48

    I think in order import namespace in razor view, you just need to add below way:

    @using XX.YY.ZZ
    
    0 讨论(0)
  • 2020-11-22 11:52

    In ASP.NET MVC 3 Preview1 you can import a namespace on all your razor views with this code in Global.asax.cs

    Microsoft.WebPages.Compilation.CodeGeneratorSettings.AddGlobalImport("Namespace.Namespace");
    

    I hope in RTM this gets done through Web.config section.

    0 讨论(0)
  • 2020-11-22 11:53

    Finally found the answer.

    @using MyNamespace
    

    For VB.Net:

    @Imports Mynamespace
    

    Take a look at @ravy amiry's answer if you want to include a namespace across the app.

    0 讨论(0)
  • 2020-11-22 11:54

    For namespace and Library

    @using NameSpace_Name
    

    For Model

    @model Application_Name.Models.Model_Name 
    

    For Iterate the list on Razor Page (You Have to use foreach loop for access the list items)

    @model List<Application_Name.Models.Model_Name>
    
    @foreach (var item in Model)
       {  
              <tr>
                    <td>@item.srno</td>
                    <td>@item.name</td>
             </tr>  
       }
    
    0 讨论(0)
提交回复
热议问题