?
Solved

Code First validation issues

Posted on 2013-01-15
7
Medium Priority
?
307 Views
Last Modified: 2013-01-16
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
0
Comment
Question by:rochestermn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 18

Accepted Solution

by:
dj_alik earned 1500 total points
ID: 38781672
Validation Error Message: http://forums.asp.net/t/1582596.aspx/1
0
 
LVL 16

Expert Comment

by:Kamal Khaleefa
ID: 38782197
try to use the required field in the same page

also put  Display="Dynamic"
0
 
LVL 22

Expert Comment

by:ambience
ID: 38782714
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?
0
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 

Author Comment

by:rochestermn
ID: 38784033
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/overview/aspnet-web-forms/aspnet-45-web-forms-model-binding

http://www.hanselman.com/blog/CommentView.aspx?guid=659B5FDC-07AA-4A46-B269-57D48F36FA30#c8d93be7-726d-4842-8e11-a88f5602a1eb
0
 

Author Comment

by:rochestermn
ID: 38784321
I think I might have found some good info here:

http://msdn.microsoft.com/en-us/library/vstudio/cc679101(v=vs.90).aspx
0
 

Author Comment

by:rochestermn
ID: 38784751
Ok so it looks like its working now.  The above link helped but there are others who suggested similar help.

Seems to be working now
0
 

Author Closing Comment

by:rochestermn
ID: 38784767
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question