简体   繁体   English

Referencing another project in .NET Core的后续

[英]Follow-up to Referencing another project in .NET Core

I'm working on a new ASP.NET MVC Core which I'm writing using .NET 6. At this point I have my main MVC project I call BookFinder.我正在开发一个新的 ASP.NET MVC 核心,我正在使用 .NET 6 编写它。此时我有我的主要 MVC 项目,我称之为 BookFinder。 Then I have a second project, which is a library project, named BookApi.然后我有第二个项目,这是一个图书馆项目,名为 BookApi。 I tried to find a way of using BookApi from BookFinder, but I haven't.我试图从 BookFinder 找到一种使用 BookApi 的方法,但我没有找到。 I did find another post from 4 years ago named Referencing another project in.Net Core which looked like it had hope, but I'm still not certain how to access BookApi from a Razor view in BookFinder.我确实找到了 4 年前的另一篇名为Referencing another project in.Net Core的帖子,它看起来很有希望,但我仍然不确定如何从 BookFinder 中的 Razor 视图访问 BookApi。 I've added a reference to BookApi in BookFinder.我在 BookFinder 中添加了对 BookApi 的引用。 That reference makes it possible for me to then add a @using statement, but I don't know how to get to a GetBooksByAuthor() method in BookApi from BookFinder.该参考使我可以添加 @using 语句,但我不知道如何从 BookFinder 获取 BookApi 中的 GetBooksByAuthor() 方法。 (GetBooksByAuthor() is declared public static in BookApi.) I've tried adding some code to the Razor view, but it doesn't let me get to GetBooksByAuthor() method of BookApi. (GetBooksByAuthor() 在 BookApi 中被声明为 public static。)我尝试向 Razor 视图添加一些代码,但它不允许我访问 BookApi 的 GetBooksByAuthor() 方法。 Here's what I've got so far这是我到目前为止所得到的

 @using BookApi @*First added a reference to this library project*@ @{ ViewData["Title"] = "Search by author"; } <div class="text-center"> <h1 class="display-4">Search by book author</h1> </div>

And here's a snippet from my Solution Explorer from Vs 2022:这是我的 Solution Explorer 来自 Vs 2022 的片段:

在此处输入图像描述

I think you could try @BookApi.GetBooksByAuthor("") in your view我认为你可以在你的视图中尝试@BookApi.GetBooksByAuthor("")

In my case:就我而言: 在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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