HOW TO VALIDATE VALIDATIONS WHETHER TEXTBOX IS EMPTY OR NOT. USING LINQ TO SQL. IN MVC

venkat gosetty

Total Post:15

Points:105
Posted by  venkat gosetty
 3181  View(s)
Ratings:
Rate this:
hi,
   how to validate validations whether textbox is empty or not. using linq to sql.

Regards,
Venkat
  1. Chris Anderson

    Post:65

    Points:455
    Re: how to validate validations whether textbox is empty or not. using linq to sql. in mvc

    hi venkat,

    if you want validate your textbox, simply use:

    namespace:
    using System.ComponentModel.DataAnnotations;

    and above the property add following:
    [StringLength(50),Required]
    public string Name { get; set; }

    why you use linq to sql for validation?

  1. venkat gosetty

    Post:15

    Points:105
    Re: how to validate validations whether textbox is empty or not. using linq to sql. in mvc

    Actually  i have taken model class .dbml (linq to sql template)

  1. Chris Anderson

    Post:65

    Points:455
    Re: how to validate validations whether textbox is empty or not. using linq to sql. in mvc

    hi,

    you can put validation using linq to sql query something like below:

    DataContext data = new DataContext();
    string value="S001";

    var query = from p in data.Persons
                       where p.Id == value
                                      select p;

    if (query.Count() > 0) throw new Exception("Id already exists in the database");

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!