私は同じ問題を抱えています。
「Microsoft .NET Framework 4.5言語パック」がAzureの「Webサイト」にインストールされていないとします。 「Azure cloudプロジェクト」を使用することは、IISを直接設定できるオプションであるようです。
別の解決策は、Azureの中で言語パックのサポートが含まれるように、マイクロソフトのを待つことです...
Personnaly、私はメインの属性を上書きすることにしました。ほとんどのトリッキーは[必須]と[正規表現]です。
using System.ComponentModel.DataAnnotations;
using System.Globalization;
namespace Ic.DataAnnotations
{
public class RegularExpressionLoc : RegularExpressionAttribute
{
private readonly string _errorMessage;
public RegularExpressionLoc(string errorMessage, string pattern)
: base(pattern)
{
_errorMessage = errorMessage;
}
public override string FormatErrorMessage(string input)
{
return Localizer.Loc(_errorMessage);
}
}
}
そして
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
namespace Ic.DataAnnotations
{
public class RegularExpressionValidator : DataAnnotationsModelValidator<RegularExpressionAttribute>
{
private readonly string _message;
private readonly string _pattern;
public RegularExpressionValidator(ModelMetadata metadata, ControllerContext context, RegularExpressionAttribute attribute)
: base(metadata, context, attribute)
{
_pattern = attribute.Pattern;
_message = attribute.FormatErrorMessage("");
}
public override IEnumerable<ModelClientValidationRule> GetClientValidationRules()
{
var rule = new ModelClientValidationRule
{
ErrorMessage = _message,
ValidationType = "regex"
};
rule.ValidationParameters.Add("pattern", _pattern);
return new[] { rule };
}
}
}
そして中
Global.asaxの
DataAnnotationsModelValidatorProvider.RegisterAdapter(typeof(RegularExpressionLoc), typeof(RegularExpressionValidator));
:下記を参照してください。正規表現の
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Web.Mvc;
namespace Ic.DataAnnotations
{
public class RequiredLoc : RequiredAttribute, IClientValidatable
{
public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata,
ControllerContext context)
{
yield return new ModelClientValidationRule
{
ErrorMessage = FormatErrorMessage(metadata.DisplayName),
ValidationType = "required"
};
}
public override string FormatErrorMessage(string message)
{
base.FormatErrorMessage(message);
return Localizer.Loc("Le champs '%1' est requis.", message);
}
}
}
(LOCは、私はgettextのを使用していますように私自身のローカライズ機能です)
あなたはそれを把握しましたか? – bob
いいえ現在、私はカスタム属性を使用しています。 – Harry