我在MVC验证有问题,我的模型有一个双重属性,当我提交10.30或任何与“。”。它里面告诉我“价值'10.30'对价格无效”。 我做了一些研究,他们说模型验证应该是文化不变的,我想这可能是问题,因为我的浏览器和服务器是法文的,但它不应该。MVC3模型验证不工作在双重
这里是我的代码:
[HttpPost]
[ValidateAntiForgeryToken]
[Authorize(Roles = "Admin")]
[ValidateInput(false)]
public virtual ActionResult Edit(AuctionModel model)
{
if (ModelState.IsValid)
{
//do the work
}
return View(model);
}
public class AuctionModel
{
public string Id { get; set; }
[Required(ErrorMessageResourceType = typeof(Strings), ErrorMessageResourceName = "FieldMandatory")]
[LocalizedDisplayName("Title")]
public string Title { get; set; }
[Required(ErrorMessageResourceType = typeof(Strings), ErrorMessageResourceName = "FieldMandatory")]
[LocalizedDisplayName("Description")]
public string Description { get; set; }
[Required(ErrorMessageResourceType = typeof(Strings), ErrorMessageResourceName = "FieldMandatory")]
[LocalizedDisplayName("Photo")]
public string Photo { get; set; }
[Required(ErrorMessageResourceType = typeof(Strings), ErrorMessageResourceName = "FieldMandatory")]
[LocalizedDisplayName("StartDate")]
public DateTime StartDate { get; set; }
[Required(ErrorMessageResourceType = typeof(Strings), ErrorMessageResourceName = "FieldMandatory")]
[LocalizedDisplayName("Price")]
public double Price { get; set; }
}
感谢您的帮助!
您是否尝试过进入'10,30'只是要仔细检查,如果它是一个文化问题? – StriplingWarrior 2011-04-21 15:07:37
是的,我仍然有一个错误:字段价格必须是一个数字。 – VinnyG 2011-04-21 15:20:20
当它与“。”它到服务器端和ModelState.IsValid = false,当它是一个“,”它不去服务器端,验证是客户端... – VinnyG 2011-04-21 15:22:09