无法从 mvc 应用程序中的其他 C# 项目获取 属性 引用
unable to get property reference from other C# project in mvc application
我创建了 one c# library project
。
我创建了 another MVC application added C# project reference into mvc application
.
现在 View
我想访问 C# class 库项目中的那个 属性 但我无法这样做,为什么?
C#项目代码
namespace Helper.BaseClasses
{
public abstract class BaseView<T> : WebViewPage<T>
{
private TestClass localizer;
public override void InitHelpers()
{
base.InitHelpers();
localizer = new TestClass();
}
public TestClass Lang
{
get { return localizer; }
}
}
}
public class TestClass
{
public string TestMethod(string input)
{
//some code
}
}
Mvc应用添加了c#的引用dll
Index.cshtml
<h4>@Lang.TestMethod("Customer agreements", "")</h4>
当我尝试在 Index.cshtml 中使用 TestMethod
时,出现错误
The name TestMethod does not exist in current context
添加 C# 项目 dll 引用后为什么会出现此错误:(
你在web.config中设置了"pageBaseType"了吗?
如果不是,请尝试将其设置为您的基础 class。
为此,您需要在 ~/Views/web.config 中找到 "pages" 标签。
它会是这样的:
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
<add namespace="WebApplication1" />
</namespaces>
</pages>
您需要将其更改为:
<pages pageBaseType="Helper.BaseClasses.BaseView">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
<add namespace="WebApplication1" />
</namespaces>
</pages>
并重建解决方案。
希望这有帮助。
我创建了 one c# library project
。
我创建了 another MVC application added C# project reference into mvc application
.
现在 View
我想访问 C# class 库项目中的那个 属性 但我无法这样做,为什么?
C#项目代码
namespace Helper.BaseClasses
{
public abstract class BaseView<T> : WebViewPage<T>
{
private TestClass localizer;
public override void InitHelpers()
{
base.InitHelpers();
localizer = new TestClass();
}
public TestClass Lang
{
get { return localizer; }
}
}
}
public class TestClass
{
public string TestMethod(string input)
{
//some code
}
}
Mvc应用添加了c#的引用dll Index.cshtml
<h4>@Lang.TestMethod("Customer agreements", "")</h4>
当我尝试在 Index.cshtml 中使用 TestMethod
时,出现错误
The name TestMethod does not exist in current context
添加 C# 项目 dll 引用后为什么会出现此错误:(
你在web.config中设置了"pageBaseType"了吗? 如果不是,请尝试将其设置为您的基础 class。 为此,您需要在 ~/Views/web.config 中找到 "pages" 标签。 它会是这样的:
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
<add namespace="WebApplication1" />
</namespaces>
</pages>
您需要将其更改为:
<pages pageBaseType="Helper.BaseClasses.BaseView">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
<add namespace="WebApplication1" />
</namespaces>
</pages>
并重建解决方案。 希望这有帮助。