无论是ErrorMessageString或ErrorMessageResourceName必须设置,但不能使用CreditCardAttribute两个错误 [英] Either ErrorMessageString or ErrorMessageResourceName must be set, but not both error using CreditCardAttribute
问题描述
这是我的模型:
namespace MvcApplication2.Models
{
public class CreditCard
{
[CreditCard(ErrorMessageResourceType = typeof(Messages), ErrorMessageResourceName = "CardNumberInvalid")]
public string CardNumber { get; set; }
}
}
这是我的Messages.resx:
This is my Messages.resx:
名称值
CardNumberInvalid检查您的信用卡号码是正确的。
CardNumberInvalid Check your card number is correct
这是我的看法:
@model MvcApplication2.Models.CreditCard
@Html.TextBoxFor(m => m.CardNumber);
在MVC 3版本的工作没有错误。在MVC 4,当我去这个页面,我得到一个错误时抛出说要么ErrorMessageString或ErrorMessageResourceName必须设置,但不能两者都。这仅与CreditCardAttribute发生。其他属性验证,如工作RequiredAttribute标签罚款。我只设置ErrorMessageResourceName。我没有设置ErrorMessageString,所以不明白我做了什么错。任何人都可以帮忙吗?
In MVC version 3 this works without error. In MVC 4 when I go to this page I get an excpetion saying "Either ErrorMessageString or ErrorMessageResourceName must be set, but not both". This is only happening with the CreditCardAttribute. Other validation attributes such as RequiredAttribute work fine. I have only set the ErrorMessageResourceName. I have not set the ErrorMessageString, so do not understand what I have done wrong. Can anyone help please?
推荐答案
这是在.NET 4.5中的已知问题。添加的ErrorMessage = NULL命名的参数应该解决这个问题。
It's a known issue in .Net 4.5. Adding "ErrorMessage = null" named parameter should solve this.
参考:
<一href=\"http://connect.microsoft.com/VisualStudio/feedback/details/757298/emailaddress-attribute-is-unable-to-load-error-message-from-resource-mvc\">http://connect.microsoft.com/VisualStudio/feedback/details/757298/emailaddress-attribute-is-unable-to-load-error-message-from-resource-mvc
这篇关于无论是ErrorMessageString或ErrorMessageResourceName必须设置,但不能使用CreditCardAttribute两个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!