Home > DeveloperSection > Forums > how to validate validations whether textbox is empty or not. using linq to sql. in mvc
venkat gosetty
venkat gosetty

Total Post:15

Points:105
Posted on    November-18-2011 3:01 AM

 ASP.NET MVC ASP.NET MVC 
Ratings:


 3 Reply(s)
 2706  View(s)
Rate this:
hi,
   how to validate validations whether textbox is empty or not. using linq to sql.

Regards,
Venkat


Chris Anderson
Chris Anderson

Total Post:65

Points:455
Posted on    November-18-2011 3:58 AM

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?

venkat gosetty
venkat gosetty

Total Post:15

Points:105
Posted on    November-22-2011 12:29 AM

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

Chris Anderson
Chris Anderson

Total Post:65

Points:455
Posted on    November-22-2011 1:42 AM

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");


Don't want to miss updates? Please click the below button!

Follow MindStick