mvc自定义验证最低价格

时间:2013-05-24 08:34:42

标签: c# asp.net-mvc validation

我有一个项目。我需要自定义验证才能找到最低价格。现在首先我的所有模型都在这里;

public class ReservationModel
{
    [Required]
    public DateTime BeginDate { get; set; }
    [Required]
    public DateTime EndDate { get; set; }
    [Required]
    public double Price { get; set; }
    [Required]
    public string EmailAddress { get; set; }
    public Guid ApartId { get; set; }
    [Required]
    public int Guest { get; set; }
    public string ApartName { get; set; }
    public string City { get; set; }
    public string Country { get; set; }
    public string AddressLine1 { get; set; }
    public string AddressLine2 { get; set; }
    public string ApartDesc { get; set; }
    [Required]
    public string FirstName { get; set; }
    [Required]
    public string LastName { get; set; }
    public string CategoryName { get; set; }

    public double MinAmount { get; set; }
    public string ApartImage { get; set; }
    public string CheckInTime { get; set; }
    public string CheckOutTime { get; set; }
    public int DayOfReservation { get; set; }
    public int ReservationGuestNumber { get; set; }




}

我想在MinAmount中使用此验证。我有动态价格。例如,单价300美元。我想MinAmount值必须是300 X 25/100 = 75 USD。验证错误消息是如果客户写入50美元或低于75美元。那么如何创建我的自定义MinPriceAttribute ???谢谢你的回复。

1 个答案:

答案 0 :(得分:0)

您可以做的是创建自定义过滤器。 您可以在mvc custom filter

找到一些提示

Video tutorial