我在使用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