| 
 | |||||||
| 
 | 
|  | 
|  | 
|  | Strumenti | 
|  27-06-2013, 11:52 | #1 | 
| Member Iscritto dal: Mar 2007 
					Messaggi: 183
				 | 
				
				[ASP.NET MVC]Consigli su Remote Validation
			 
		Buongiorno. Sto sviluppando un progetto con Asp.net MVC 4. Ho creato, per verificare che l'id di un elemento non sia già stato inserito, un ValidationController con il seguente codice: Codice: [OutputCache(Location = OutputCacheLocation.None, NoStore = true)]
    public class ValidationController : Controller
    {
        private RifiutiEntities db = new RifiutiEntities();
        //Codice per la validazione del campo ID_FUSTO, per verificare se è già stato inserito.
        public JsonResult IsIDFUSTOAvailable(string ID_FUSTO)
        {
            if (!PresenzaIDFUSTO(ID_FUSTO))
                return Json(true, JsonRequestBehavior.AllowGet);
            else
            {
                return Json("Attenzione, l'identificativo  " + ID_FUSTO + " è già stato inserito.", JsonRequestBehavior.AllowGet);
            }
        }
        private bool PresenzaIDFUSTO(string ID_FUSTO)
        {
            var fusto = db.TBL_NUOVO_FUSTO.FirstOrDefault(f => f.ID_FUSTO == ID_FUSTO);
            return (fusto != null);
        }Codice: [Required]
        [Display(Name = "ID_FUSTO")]
        [Remote("IsIDFUSTOAvailable", "Validation")]//Codice per validazione ID già presente
        public string ID_FUSTO { get; set; }In debug, con il seguente codice: Codice: [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(TBL_NUOVO_FUSTO tbl_nuovo_fusto)
        {
            
            if (ModelState.IsValid)
            {
                db.TBL_NUOVO_FUSTO.Add(tbl_nuovo_fusto);
                db.SaveChanges();
                return RedirectToAction("Index");
            }Qualche consiglio? | 
|   |   | 
|   | 
| Strumenti | |
| 
 | 
 | 
Tutti gli orari sono GMT +1. Ora sono le: 09:13.









 
		 
		 
		 
		






 
  
 



 
                        
                        










