简体   繁体   中英

Referencing classes in a Razor Class Library

I created a new Razor Class Library (using "dotnet new razorclasslib"). I then created a folder called Models in the new library and it contains a class with the following test code:

using System;

namespace TestLibrary.Models
{
    public class TestModel
    {
        public string TestMethod { get; set; }
    }
}

However, when I try to use this class from the web application project (by referring to it as TestLibrary.Models.TestModel ) I keep being told that the TestLibrary.Models namespace doesn't exist. The exact error is:

The type or namespace name 'Models' does not exist in the namespace 'TestLibrary' (are you missing an assembly reference?) [TestApplication]

I'm assuming I'm missing something simple, just can't figure out what.

This issue was somehow related to the issue posted here: Razor Class Library MSBuild MSB4062 Error During Compile . Once that was resolved this issue went away.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM