English 中文(简体)
MVC 3 带有数据说明的弹 Raz
原标题:Localizing an MVC 3 Razor app with Data Annotations
  1. 我想能为正在使用的具体文化展示错误信息。

  2. 我有一个使用数据年度的模型,我还有若干资源(resx)文档,有相同的错误信息,但使用不同的语言。

  3. 我知道,我需要从数据说明与我资源档案中的信息的伊德有某种联系,但对于如何做到这一点,各辛迪加没有把握。

例如,我有以下数据年度报告。 我需要把傲慢案文与我的资源档案中的具体关键内容联系起来。 在执行第3步时需要考虑什么?

在添加语句中,对于像日记代码或电话号码这样的领域(如果它有不同的定期表述),我是否必须从模型中提取信息,并将其应用于正在使用该模型的每一种观点?

或者,是否有办法规定在模型中可以使用哪些定期表述?

using System;
using System.ComponentModel.DataAnnotations;
using DataAnnotationsExtensions;

namespace YeagerTechModel
{
    [MetadataType(typeof(Customer_Validation))]
    public partial class Customer
    {

    }

    public partial class Customer_Validation
    {
        public short CustomerID { get; set; }

        [Required]
        [StringLength(50)]
        [DataType(DataType.EmailAddress)]
        [Email]
        public string Email { get; set; }

        [StringLength(50, MinimumLength = 3, ErrorMessage = "Must have a minimum length of 3.")]
        [DataType(DataType.Text)]
        public string Company { get; set; }

        [StringLength(50, MinimumLength = 3, ErrorMessage = "Must have a minimum length of 3.")]
        [DataType(DataType.Text)]
        public string FirstName { get; set; }

        [StringLength(50, MinimumLength = 3, ErrorMessage = "Must have a minimum length of 3.")]
        [DataType(DataType.Text)]
        public string LastName { get; set; }

        [StringLength(50, MinimumLength = 3, ErrorMessage = "Must have a minimum length of 3.")]
        [DataType(DataType.Text)]
        public string Address1 { get; set; }

        [StringLength(50)]
        [DataType(DataType.Text)]
        public string Address2 { get; set; }

        [StringLength(50, MinimumLength = 3, ErrorMessage = "Must have a minimum length of 3.")]
        [DataType(DataType.Text)]
        public string City { get; set; }

        [StringLength(2, MinimumLength = 2, ErrorMessage = "Must have a length of 2.")]
        [DataType(DataType.Text)]
        public string State { get; set; }

        [StringLength(10)]
        [DataType(DataType.Text)]
        [RegularExpression(@"^d{5}(-d{4})?$", ErrorMessage = "Invalid Zip")]
        public string Zip { get; set; }

        [StringLength(12)]
        [DataType(DataType.PhoneNumber)]
        [RegularExpression(@"^s*([(]?)[?s*d{3}s*]?[)]?s*[-]?[.]?s*d{3}s*[-]?[.]?s*d{4}$", ErrorMessage = "Invalid Phone")]
        public string HomePhone { get; set; }

        [StringLength(12)]
        [DataType(DataType.PhoneNumber)]
        [RegularExpression(@"^s*([(]?)[?s*d{3}s*]?[)]?s*[-]?[.]?s*d{3}s*[-]?[.]?s*d{4}$", ErrorMessage = "Invalid Phone")]
        public string CellPhone { get; set; }

        [StringLength(100)]
        [DataType(DataType.Url)]
        [Url]
        public string Website { get; set; }

        [StringLength(50)]
        [DataType(DataType.EmailAddress)]
        [Email]
        public string IMAddress { get; set; }

        public System.DateTime CreatedDate { get; set; }

        public Nullable<System.DateTime> UpdatedDate { get; set; }
    }
}
问题回答




相关问题
Bind Button.IsEnabled to custom validation with XAML?

I am sorry I didn t know how to title my question any better, you name it if you got a good 1. I have an entity Contact. this person has navigation properties: Address, Phones (A collection of Phone)....

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

Wpf Combobox Limit to List

We are using Wpf Combobox to allow the user to do the following things: 1) select items by typing in the first few characters 2) auto complete the entry by filtering the list 3) suggesting the first ...

Rails 101 | validates_currency?

I ve searched high and low, but I could not find a solution, to what I think seems like a very common task. In a form I want to have a text input that accepts currency strings (i.e. $1,000,000 or ...

CodeIgniter form verification and class

I m using the form validation library and have something like this in the view <p> <label for="NAME">Name <span class="required">*</span></label> <?...

热门标签