rochestermn
asked on
Code First validation issues
Im having a difficult time getting the required field error message to behave properly in my code first model.
What happens is when i click a submit button to add a record all I see are asterisks. But I have custom error messages and none of them show up.
Is there anyway to override this behavior? Even will use javascript if I have to.
Please see 3 attached screens showing ui markup(formview), model code, and the resulting page when run.
Capture.JPG
Capture2.JPG
Capture3.JPG
What happens is when i click a submit button to add a record all I see are asterisks. But I have custom error messages and none of them show up.
Is there anyway to override this behavior? Even will use javascript if I have to.
Please see 3 attached screens showing ui markup(formview), model code, and the resulting page when run.
Capture.JPG
Capture2.JPG
Capture3.JPG
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I'm not sure about the aspx page syntax but in razor you need to add the ValidationSummary markup to the page like
<div class="editor-field">
@Html.PasswordFor(m => m.OldPassword)
@Html.ValidationMessageFor (m => m.OldPassword)
</div>
Can you check whether you are missing the corresponding markup?
<div class="editor-field">
@Html.PasswordFor(m => m.OldPassword)
@Html.ValidationMessageFor
</div>
Can you check whether you are missing the corresponding markup?
ASKER
For the record this is .net 4.5 and vs 2012 and im basing my project off a concept that scott hanselman from microsoft blogged about recently called model binding with webforms.
Ive done mvc in the past but im not yet ready to forget the convenience of controls that webforms offer. So thats why scotts example intrigued me. In the past I just added the required attribute to the model and the validation was automatically there. There wasnt a need for any validation summary or required field validators. Im also using DynamicControls for the text boxes. These are inside a formview. See attached screenshot above showing my markup.
Here are the links to scotts demos.
http://www.asp.net/vnext/o verview/as pnet-web-f orms/aspne t-45-web-f orms-model -binding
http://www.hanselman.com/b log/Commen tView.aspx ?guid=659B 5FDC-07AA- 4A46-B269- 57D48F36FA 30#c8d93be 7-726d-484 2-8e11-a88 f5602a1eb
Ive done mvc in the past but im not yet ready to forget the convenience of controls that webforms offer. So thats why scotts example intrigued me. In the past I just added the required attribute to the model and the validation was automatically there. There wasnt a need for any validation summary or required field validators. Im also using DynamicControls for the text boxes. These are inside a formview. See attached screenshot above showing my markup.
Here are the links to scotts demos.
http://www.asp.net/vnext/o
http://www.hanselman.com/b
ASKER
I think I might have found some good info here:
http://msdn.microsoft.com/ en-us/libr ary/vstudi o/cc679101 (v=vs.90). aspx
http://msdn.microsoft.com/
ASKER
ASKER
This link helped along with experts link.
http://msdn.microsoft.com/en-us/library/vstudio/cc679101(v=vs.90).aspx
http://msdn.microsoft.com/en-us/library/vstudio/cc679101(v=vs.90).aspx
also put Display="Dynamic"