Validating ASP.NET MVC Forms with DataAnnotations

Validating ASP.NET MVC Forms with DataAnnotations

Michael Kennedy

11 лет назад

24,182 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Luke Robinett
Luke Robinett - 27.05.2020 23:17

Hey Michael. Thanks for the video. I'm teaching myself .NET Core and am trying to get a very simple .Net Core Razor Pages test app to work. It has two pages - a form entry page and a confirmation page that basically says whatever was entered on the form. There's no db or Entity layer here, just a straight post to the confirmation page, so as simple as it can get. I have a Person class in my Models folder. A Person has three props: FirstName, LastName and EmailAddress. I have validation annotations for each of them, including that each is required. When the user clicks Submit, the app accepts the fields even when they're blank or violate other validation rules I've added. ModelState.IsValid always seems to evaluate to True no matter what. I notice that my data entry page has @model set to the page model, understandably, but this makes me think perhaps Visual Studio is never even trying to validate the Person model. The way I associate the Person model with the form is adding it as a property to the page model, like Public Person = Person { get; set; } and preceeding that with a [BindProperty] decoration. Based on what I've described here, any ideas on why my Person class never gets validated?

Ответить
noobzzzz
noobzzzz - 05.08.2016 23:00

u need to add these lines in app settings of web.config for the client side validation to work
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />

took me hours of searching to find

Ответить
Michael James
Michael James - 07.02.2016 12:28

very helpful. Thanks Michael

Ответить
卡门山迪亚戈
卡门山迪亚戈 - 10.08.2015 21:59

Thanks very much,the tutorial is easy to understand.

Ответить
mayank bisht
mayank bisht - 09.04.2015 19:03

hye , please explain how to validate dropdownlist. ? 

Ответить
judgewest2000
judgewest2000 - 18.10.2014 20:27

Excellent!!!
Thank you for taking the time to make this vid!

Ответить
I'm definitely not the devil
I'm definitely not the devil - 03.10.2014 18:32

I've found gold!

Ответить
jaseena.r rahila
jaseena.r rahila - 18.09.2014 10:05

All your turtorials are Gem !!!

Ответить
Patrick Louie Cute Flores
Patrick Louie Cute Flores - 25.07.2014 12:40

how do you fix a entity validation property error?

Ответить
Bernhard Hofmann
Bernhard Hofmann - 13.06.2014 11:05

Excellent introduction to data annotations.

Ответить
Daniel A.
Daniel A. - 04.03.2014 21:55

Great tutorial!  The subject matter itself is not all that intuitive with all that indirection, but your explanation was very helpful and easy to follow.

Ответить
Erro58
Erro58 - 07.04.2013 22:28

Thank you man! this was very helpful!

Ответить
Tamara Čuček
Tamara Čuček - 06.04.2013 20:17

Can you send me a project please?

Ответить
Anuradha Jayaraman
Anuradha Jayaraman - 24.03.2013 18:02

Great !

Ответить
Dhriti
Dhriti - 27.01.2013 11:11

nice tutorial, thank u

Ответить