我在使用DropDownList验证的ASP.NET MVC中遇到问题。 我有两个操作“创建”。它们的定义如下:DropDownList验证 - 问题
public ActionResult Create()
{
var categoriasDownloads = from catDown in modelo.tbCategoriasDownloads
orderby catDown.TituloCategoriaDownload ascending
select catDown;
ViewData["CategoriasDownloads"] = new SelectList(categoriasDownloads, "IDCategoriaDownloads", "TituloCategoriaDownload");
var formatosArquivos = from formatosDown in modelo.tbFormatosArquivos
orderby formatosDown.NomeFormatoSigla
select formatosDown;
ViewData["FormatosArquivos"] = new SelectList(formatosArquivos, "IDFormatoArquivo", "NomeFormatoSigla");
return View();
}
,第二个操作创建为:
[HttpPost]
public ActionResult Create(tbDownloads _novoDownload)
{
TryUpdateModel(modelo);
TryUpdateModel(modelo.tbDownloads);
if (ModelState.IsValid)
{
modelo.AddTotbDownloads(_novoDownload);
modelo.SaveChanges();
return RedirectToAction("Sucesso", "Mensagens");
}
return View(_novoDownload);
}
的问题是:当试图验证,不会发生验证。我正在使用数据注释进行验证,但我还没有成功。
我该怎么办?
谢谢
发表您的数据注释代码,请 – Arief 2010-10-29 14:09:27