Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Just wondering how to deal with regionalised labels & validation in a custom controller
[Required(ErrorMessage = "City is required")]
[Display(Name = "City*")]
public string City { get; set; }
How can I translate the Name and ErrorMessage with the DictionaryItems in my Custom Controller?
umbraco.library.GetDictionaryItem("City") ain't working... umbraco.library.GetDictionaryItem(“City”); either
uQuery.GetDictionaryItem("Key", "FallbackValue", languageId)
This gives me "cannot resolve symbol GetDictionaryItem"
If this inside an project you need to add reference to the umbraco.dll
I have referenced the umbraco.dll, but I'm using the dataannotions in a seperate model class, and I'm using that model in my controller. I didn't describe the issue correctly in my initial question I think.
Aha, got it;
I have extended the required attribute on my project so that it grabs the error message from the dictionary:
Add new Item >> new class >> LocalizedRequiredAttribute.cs
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
namespace xxx.Website
{
public class LocalizedRequiredAttribute : RequiredAttribute, IClientValidatable
public override string FormatErrorMessage(string name)
return umbraco.library.GetDictionaryItem(this.ErrorMessage);
}
public IEnumerable GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
yield return new ModelClientValidationRule
// format the error message to include the property's display name.
ErrorMessage = FormatErrorMessage(metadata.DisplayName),
// uses the required validation type.
ValidationType = "required"
};
Then, on my model I just decorate the error message:
[LocalizedRequired(ErrorMessage = "XXXRequired")]
This solution doesn't seem to be working in later versions of Umbraco 7.1.*, 7.2.*.
Has anyone come across this and have any solutions?
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.
Continue discussion
Using Dictionary items in a SurfaceController
Just wondering how to deal with regionalised labels & validation in a custom controller
[Required(ErrorMessage = "City is required")]
[Display(Name = "City*")]
public string City { get; set; }
How can I translate the Name and ErrorMessage with the DictionaryItems in my Custom Controller?
umbraco.library.GetDictionaryItem("City") ain't working... umbraco.library.GetDictionaryItem(“City”); either
uQuery.GetDictionaryItem("Key", "FallbackValue", languageId)
This gives me "cannot resolve symbol GetDictionaryItem"
If this inside an project you need to add reference to the umbraco.dll
I have referenced the umbraco.dll, but I'm using the dataannotions in a seperate model class, and I'm using that model in my controller. I didn't describe the issue correctly in my initial question I think.
Aha, got it;
I have extended the required attribute on my project so that it grabs the error message from the dictionary:
Add new Item >> new class >> LocalizedRequiredAttribute.cs
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
namespace xxx.Website
{
public class LocalizedRequiredAttribute : RequiredAttribute, IClientValidatable
{
public override string FormatErrorMessage(string name)
{
return umbraco.library.GetDictionaryItem(this.ErrorMessage);
}
public IEnumerable GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
{
yield return new ModelClientValidationRule
{
// format the error message to include the property's display name.
ErrorMessage = FormatErrorMessage(metadata.DisplayName),
// uses the required validation type.
ValidationType = "required"
};
}
}
}
Then, on my model I just decorate the error message:
[LocalizedRequired(ErrorMessage = "XXXRequired")]
This solution doesn't seem to be working in later versions of Umbraco 7.1.*, 7.2.*.
Has anyone come across this and have any solutions?
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.