我正在使用asp.net mvc 4我在我的模型中使用[maxlength(2)]但是它不能用于客户端验证我是asp.net mvc的新手.这是我的代码.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace RestrauntsMVC.Models
{
public class Restraunts
{
public int id { get; set; }
[Required]
public string name { get; set; }
[Required]
[MaxLength(2),MinLength(1)]
public int rating { get; set; }
[Required]
public string location { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
我发现答案myslef它工作Maxlength和minlength是String不是整数.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
namespace RestrauntsMVC.Models
{
public class Restraunts
{
public int id { get; set; }
[Required]
public string name { get; set; }
[Required]
[Range(1,10,ErrorMessage="Rating must between 1 to 10")]
public int rating { get; set; }
[Required]
public string location { get; set; }
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6519 次 |
| 最近记录: |