开发者

Constants and aspx

开发者 https://www.devze.com 2023-01-03 09:34 出处:网络
I have constants in my cs file Constants.cs.In the asp.net mvc controllers I use the constants like this ViewData[Constants.Whatever] = ...;

I have constants in my cs file Constants.cs. In the asp.net mvc controllers I use the constants like this ViewData[Constants.Whatever] = ...;

How can I use the constants in my aspx file? When I try to use it I get an error saying:

CS0103: The name 'C开发者_开发知识库onstants' does not exist in the current context


Add the namespace of class on the web.config so it can recognize it ... probably


Something like this should work:

<%@ Import Namespace="System.Collections.Generic" %>

Change System.Collections.Generic with the namespace where you declare your Contants.cs code file so that it gets into the scope.


What namespace is your Constants class is in? You have to import it; say it's Foo.App.Constants (i.e. namespace Foo.App), you'll want to add

 <%@ Import Namespace="Foo.App" %>

to the top of your aspx file.

0

精彩评论

暂无评论...
验证码 换一张
取 消