मुझे एक ही समस्या है।
मुझे लगता है कि "माइक्रोसॉफ्ट .NET Framework 4.5 भाषा पैक" Azure "वेब साइट्स" पर स्थापित नहीं है। ऐसा लगता है कि "एज़ूर क्लाउड प्रोजेक्ट" एक विकल्प है क्योंकि आप आईआईएस को सीधे कॉन्फ़िगर कर सकते हैं।
एक अन्य समाधान माइक्रोसॉफ्ट के लिए प्रतीक्षा करने 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 का उपयोग कर रहा है)
स्रोत
2014-01-09 20:55:19
क्या आपने इसे समझ लिया? – bob
नहीं। वर्तमान में मैं कस्टम विशेषताओं का उपयोग करता हूं। – Harry