I have 5 to 6 projects. Project A and B use a same file via Linked File. Now, if I use this class in Razor I will get,
我有5到6个项目。项目A和项目B通过链接文件使用相同的文件。如果我在Razor中使用这门课,我会得到,
The call is ambiguous between the following methods or properties:
Because Razor views reference all the dlls in bin. It is referencing the same class from Project A and B. How to tell the Razor during compilation use Project A and not Project B?
因为Razor视图引用bin中的所有dll。它引用了来自项目A和B的同一个类。如何在编译使用项目A而不是项目B时告诉Razor ?
4 个解决方案
#1
6
You should not use Linked Files when including the assembly too. Why do you need the referenced class twice? There is no point in that.
当包含程序集时,不应该使用链接文件。为什么需要引用类两次?这是没有意义的。
You have to put that file in a separate project and reference that one in A, B and your MVC project. This makes you don't need the linked files any more.
您必须将该文件放在一个单独的项目中,并在a、B和您的MVC项目中引用该文件。这使您不再需要链接的文件。
Another way is to get the assembly and from this assembly, get the type using reflection and then call the method.
另一种方法是获取程序集,然后从这个程序集中使用反射获取类型,然后调用该方法。
#2
0
I know it's kind a tricky answer but you can add another class in one of your two projects and this class will just inherit from your shared class.
我知道这是个棘手的问题,但是你可以在两个项目中添加一个类,这个类将从你的共享类继承。
Then you can use this new class in the Razor without any problems
然后你就可以在剃须刀中使用这个新类了
#3
-1
You should use the full namespace
您应该使用完整的名称空间
Solution.ProjectA.MyClass
#4
-1
ASP.NET Razor Views allow you to use using statements just like you would in a normal cs class. You just need to add the @ symbol
ASP。NET Razor视图允许你像使用普通cs类一样使用语句。您只需要添加@符号
@using MyNamespace.ProjectA
It will work the same as a cs class.
它将和cs类一样工作。
#1
6
You should not use Linked Files when including the assembly too. Why do you need the referenced class twice? There is no point in that.
当包含程序集时,不应该使用链接文件。为什么需要引用类两次?这是没有意义的。
You have to put that file in a separate project and reference that one in A, B and your MVC project. This makes you don't need the linked files any more.
您必须将该文件放在一个单独的项目中,并在a、B和您的MVC项目中引用该文件。这使您不再需要链接的文件。
Another way is to get the assembly and from this assembly, get the type using reflection and then call the method.
另一种方法是获取程序集,然后从这个程序集中使用反射获取类型,然后调用该方法。
#2
0
I know it's kind a tricky answer but you can add another class in one of your two projects and this class will just inherit from your shared class.
我知道这是个棘手的问题,但是你可以在两个项目中添加一个类,这个类将从你的共享类继承。
Then you can use this new class in the Razor without any problems
然后你就可以在剃须刀中使用这个新类了
#3
-1
You should use the full namespace
您应该使用完整的名称空间
Solution.ProjectA.MyClass
#4
-1
ASP.NET Razor Views allow you to use using statements just like you would in a normal cs class. You just need to add the @ symbol
ASP。NET Razor视图允许你像使用普通cs类一样使用语句。您只需要添加@符号
@using MyNamespace.ProjectA
It will work the same as a cs class.
它将和cs类一样工作。