In this Code Project article which uses C#
(link to article) the author shows a Data Annotation as below: (about halfway down the linked page in a yellow code section)
My naming is slightly different: The name of my error string is FirstNameRequired instead of the author's NameRequiredError. My resource file is "ErrorMessages.resx" where the author's is named "resources.resx". Unfortunately the author's resource file
is named the same as the keyword "Resources" that is in my project's Intellisense. Although these names are different, as I type each term in the line above, everything shows up just fine in Intellisense so I'm assuming my references are being setup correctly.
But Visual Studio complains about the assignment above saying:
Constant expression is required
I was successful using that same error message from the default resource file named "ErrorMessages.resx" with the following line:
In the Code Project article I've referenced, about a screen scroll above the line I showed at the top of this post, there is a Solutions Explorer screen shot with a Class library where the author's .resx files are being kept. I don't have that because the
Visual Studio web site instructs to create the .resx files in a folder called App_GlobalResource (link).
So my question is why can't I reference the elements of my resource file in a similar way to the Code Project article without the error message?
Member
34 Points
92 Posts
Why does the VB Data Annotation not accept a reference to my resource file error message?
Sep 09, 2014 12:55 PM|Alan L|LINK
Hi,
VS2013, VB, working with MVC 5
In this Code Project article which uses C# (link to article) the author shows a Data Annotation as below: (about halfway down the linked page in a yellow code section)
I thought the equivalent VB would be:
My naming is slightly different: The name of my error string is FirstNameRequired instead of the author's NameRequiredError. My resource file is "ErrorMessages.resx" where the author's is named "resources.resx". Unfortunately the author's resource file is named the same as the keyword "Resources" that is in my project's Intellisense. Although these names are different, as I type each term in the line above, everything shows up just fine in Intellisense so I'm assuming my references are being setup correctly.
But Visual Studio complains about the assignment above saying:
I was successful using that same error message from the default resource file named "ErrorMessages.resx" with the following line:
In the Code Project article I've referenced, about a screen scroll above the line I showed at the top of this post, there is a Solutions Explorer screen shot with a Class library where the author's .resx files are being kept. I don't have that because the Visual Studio web site instructs to create the .resx files in a folder called App_GlobalResource (link).
So my question is why can't I reference the elements of my resource file in a similar way to the Code Project article without the error message?
Thanks.
Best Regards,
Alan
Member
30 Points
15 Posts
Re: Why does the VB Data Annotation not accept a reference to my resource file error message?
Sep 15, 2014 03:57 AM|adian_J|LINK
Hi,
Please have a look at resource below.
#http://www.asp.net/mvc/tutorials/mvc-music-store/mvc-music-store-part-6
#http://www.youtube.com/watch?v=duj5OMWbfDA
Hope these links give you the way to fix the issue.
Regards
Member
34 Points
92 Posts
Re: Why does the VB Data Annotation not accept a reference to my resource file error message?
Sep 15, 2014 04:01 PM|Alan L|LINK
Adian,
Thanks for those links, but they both refer to C#, and my question is trying to determine the VB equivalent.
Best Regards,
Alan