I'm creating a login form, I started with the Build in form from Umbraco.
But i want a error messaged bassed on the language..
So i made a a CustomLoginModel.
and in the model i want the error message to use Dictionary items.
But i get this error
The type or namespace name 'GetDictionaryValue' does not exist in the namespace 'Umbraco' (are you missing an assembly reference?)
public class CustomLoginModel
{
[Required(ErrorMessage = Umbraco.GetDictionaryValue("Username is missing")), Display(Name = Umbraco.GetDictionaryValue("Username"))]
public string Username { get; set; }
public string Password { get; set; }
public string RedirectUrl { get; set; }
}
David's answer is a great example. Short answer, you can't use function evaluations as parameters to attributes - i.e. you can't do Umbraco.GetDictionaryValue() as your ErrorMessage, in the same way you couldn't use Request.Url or any other parameters. Values passed to attributes must be values or value types (e.g. const values or structs).
David's answer is the way to go, then you would do:
public class CustomLoginModel
{
[UmbracoRequiredLocalised("Username is missing"), Display(Name = Umbraco.GetDictionaryValue("Username"))]
public string Username { get; set; }
public string Password { get; set; }
public string RedirectUrl { get; set; }
}
This way the UmbracoRequiredLocalised would be invoked at runtime, and get the dictionary parameter you wanted.
There is a good GitHub from Warren Buckley which can help you do this. I have used this in the past and it is very good. It uses Dictionary Items to store the language specific error messages
https://github.com/warrenbuckley/Umbraco-Validation-Attributes
Use Dictionary item in Model
Hi
I'm creating a login form, I started with the Build in form from Umbraco. But i want a error messaged bassed on the language..
So i made a a CustomLoginModel.
and in the model i want the error message to use Dictionary items.
But i get this error The type or namespace name 'GetDictionaryValue' does not exist in the namespace 'Umbraco' (are you missing an assembly reference?)
Hi Amalie
Have you included the "using Umbraco.Core" ? I think it is the namespace.
You could also use UmbracoHelper to get dictionary items.
/Bjarne
Hi Bjarne
no I had not included Umbraco.Core but the error is still there.
I haved tried Umbraco.Web
Okay, what if you create another dictionary item "UsernameIsMissing" without spaces?
Not sure if it solves the issue, but usually I don't use spaces in dictionary item keys.
/Bjarne
That does change anything. But thanks the suggestions
Can you try including using Umbraco.Web.Mvc or Umbraco.Web.UnbracoHelper?
https://our.umbraco.org/Documentation/Reference/Templating/Mvc/views
/Bjarne
Hi Amalie,
i wouldn't recommend using the dictionary like this and i'm quite sure this isn't possible at all.
What I had done to achieve this was to create custom data annotations which are using the dictionary to provide the messages.
Can't provide example right now cause in mobile but update as soon as possible.
Regards David
Hi Amalie,
as said here is an example of a custom required annotation that uses the umbraco dictionary.
Regards David
Hi Amalie,
David's answer is a great example. Short answer, you can't use function evaluations as parameters to attributes - i.e. you can't do Umbraco.GetDictionaryValue() as your ErrorMessage, in the same way you couldn't use Request.Url or any other parameters. Values passed to attributes must be values or value types (e.g. const values or structs).
David's answer is the way to go, then you would do:
This way the UmbracoRequiredLocalised would be invoked at runtime, and get the dictionary parameter you wanted.
Is there a specific using I should add to my model. I get an error saying Helper does not contain a definition for GetDictionnaryItem
There is a good GitHub from Warren Buckley which can help you do this. I have used this in the past and it is very good. It uses Dictionary Items to store the language specific error messages https://github.com/warrenbuckley/Umbraco-Validation-Attributes
Thanks!
is working on a reply...