locked
How to simulate ModelState.IsValid in any application for any model validation RRS feed

  • Question

  • User264732274 posted

    in asp.net mvc the people validate model this below way

    using System;
    using System.Data.Entity;
    using System.ComponentModel.DataAnnotations;
    
    namespace MvcMovie.Models {
        public class Movie {
            public int ID { get; set; }
    
            [Required]
            public string Title { get; set; }
    
            [DataType(DataType.Date)]
            public DateTime ReleaseDate { get; set; }
    
            [Required]
            public string Genre { get; set; }
    
            [Range(1, 100)]
            [DataType(DataType.Currency)]
            public decimal Price { get; set; }
    
            [StringLength(5)]
            public string Rating { get; set; }
        }
    
        public class MovieDBContext : DbContext {
            public DbSet<Movie> Movies { get; set; }
        }
    }
    
    if (ModelState.IsValid)
        {
            db.Movies.Add(movie);
            db.SaveChanges();
            return RedirectToAction("Index");
        }
    
    

    now guide me how could do the model validation same way in any c# win and webform application ? guide me in details. thanks

    Sunday, March 29, 2015 4:45 AM

Answers

All replies