[RESOLVED]Apply validation

thanks resolved…also I need to show Id of ..which is auto generated ..I need to show on screen

though it display error meessags of validation  but whilt it saving it gives code first error

The model backing the ‘StudentDBContext’ context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).

MVC 4

  • I have simple MVCprogram  in running condition..just inputting name..but I need to apply validation for name ..where I have to apply code ..for required name

In your model class, use the [Required] attribute on your Name property.  Remember to scope the System.ComponentModel.DataAnnotations namespace in your code file.

Help Required ..or let me know to post actual problem once more

Hi,

As Careed said that you need add required attribute.

[Required]
public string Name{get;set;}
 @Html.TextBoxFor(m => m.Name, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.Name, "", new { @class = "text-danger" })

Best Regards

Starain

in which class should I need put following two lines

@Html.TextBoxFor(m => m.Name, new { @class = "form-control" })
@Html.ValidationMessageFor(m => m.Name, "", new { @class = "text-danger" })

erum

in which class should I need put following two lines

@Html.TextBoxFor(m => m.Name, new { @class = "form-control" })

@Html.ValidationMessageFor(m => m.Name, "", new { @class = "text-danger" })

They go into your View file.  Are you not using ASP.NET MVC?

Leave a Reply