从模型中的必填字段错误消息中添加参数 [英] Add Parameter in Required Field Error Message from Model

查看:87
本文介绍了从模型中的必填字段错误消息中添加参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨专家,



我有一个模型Passenger,其中有Fname属性,其中包含必填字段验证器及其错误消息。

在错误消息中有一个参数选项,我想发送Model的Id字段。这已经在模型和视图中都有了。

所以请在客户端验证中如何实现。



  public   class 乘客
{
public Passenger( int counter)
{
Id = counter;
}
public int ID {获得; set ; }
[必需(ErrorMessage = 请提供旅行者姓名{0}]
public string Fname { get ; set ;}
}







感谢先进的

解决方案





可能你应该使用自定义验证为此。

这是一个链接 http://www.dotnetcurry.com/ShowArticle。 aspx?ID = 776 [自定义验证

Hi Experts,

I have a model Passenger in which have Fname Property in which have Required Field Validator and its error message.
In error message having a parameter option where i want to send the Id field of Model. which is already having in model and view both.
so please how can it possible in client side validation.

public class Passenger
  {
      public Passenger(int counter)
      {
      Id = counter;
      }
      public int Id { get; set; }
      [Required(ErrorMessage= "Please Provide the Name of Traveler {0}" ]
      public string Fname { get; set; }
  }




thanks in advanced

解决方案

Hi,

Probably u should be using custom validation for that.
Here's a link http://www.dotnetcurry.com/ShowArticle.aspx?ID=776[Custom Validation]


这篇关于从模型中的必填字段错误消息中添加参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆