Last post Sep 08, 2014 05:38 PM by Alan L
Sep 08, 2014 03:45 PM|Alan L|LINK
VS2013, VB, MVC 5
This is part of my Class code:
Public Class Order
Private mFirstName As String
Public Property FirstName() As String
Set(ByVal value As String)
mFirstName = value
I want to setup a resource file to allow country changes for error messages and the first attribute I am working with is <Required>. What would I write to have the error message pulled from a resource file named ErrorMessages.resx?
Broader guidance to find a location where I can understand the syntax for all of the VB data annotations would be helpful.
Sep 08, 2014 05:10 PM|Alan L|LINK
Adding to my post above, it seems to use a resource file I must set the following properties for the <Required> attribute:
ErrorMessageResourceName (key to lookup the error message Name string in my resource file)
ErrorMessageResourceType (type for the resource file, where Visual Studio automatically created Resources.ErrorMessages as seen below)
I took the above from:
So I wrote the following line, but don't understand the syntax and what it does at the end where you can see '????':
<Required(ErrorMessageResourceName:="FirstNameRequired", ErrorMessageResourceType:=TypeOf (Resources.ErrorMessages) Is ????)>
The C# equivalent for this seems to be:
Note: The order of the properties were purposely reversed in this above.
Sep 08, 2014 05:38 PM|Alan L|LINK
So, I managed to find what needed to be written and I show it below:
Figuring this out was brutal. I really just stumbled onto an obscure web page from 2005 where someone was explaining the VB.NET equivalent of the C# typeof() operator. None of the more recent explanations of VB's "TypeOf() IS <whatever>" seem even remotely
close to the answer above. Is it just the case I let the Visual Studio error messages push me in a wrong direction?
If anyone has any counsel or guidance regarding the specific syntax for <Required> it would surely be appreciated, but since I found the solution to this specific question...
I would like to also ask for counsel or guidance on how I might 'get more targeted' when searching for proper syntax for various VB.NET operators, especially as it relates to asp.net and MVC 5 programming. The web page for the <Required> attribute (MSDN
page) didn't seem to point me anywhere near the solution above, which leaves me wondering how I should actually go about finding answers for the more arcane solutions in VB.