Search code examples
c#razorgenerator

How to Create a List<TSource> for Razor-generated .cshtml files


In relation to my previous question, I want to set the returned List<Class1> listClass in my .cshtml file. However, I cannot create the following code in the .cshtml file since it does not recognize the Class1 class:

@ { 
    List<Class1> listClass = new List<Class1>();
}

<html>
    <!-- code for the view goes here -->
</html>

Class1 and the .cshtml file are located in different namespaces. Any help will be greatly appreciated.


Solution

  • Add the namespace your Class1 is located in, in a @using statement

    How do I import a namespace in Razor View Page?