Asp.net MVC form validation Related -


I do not know if people have already asked this question or did they not see this problem or whatever is.

I want to make a type view firmly for each created scene.

I am validating the form on the server side by creating a partial square of the LINQ class units.

By adding the function

Public IEnumerable & lt; Rule Violation & gt; GetRuleViolations Returns New Rule Violations ("Name Required", "Name"); If (String.IsNullOrEmpty (Name)) Returns New String Violation ("Date Required") (string.isnaloractyty (date.tostring)) Break the yield;;

Problem :

If the length of the name field is Varchar2 (10), and the user from this limit If the more names enter, the product name (see image) will be named as the empty string.

Other problems If something like the date does not enter a user date, then something like that of the object will be 1/1/0001.

Summary: should we use this method? Or to use the method to obtain all the elements using formulation or request ... Form ...

Do you give me the best advice for this?

See also

Many numbers of this problem Avit solutions.

  • For Strings: Use Vailetrs using reflection to get the maximum length of the string column attributes I LINQ entity properties and See. Alternatively, you can handle the error on joining if the column is scaled down.

  • For dates: You can do a prudent inquiry on the date (i.e., the appropriate date should be after some date) by the user or for those dates Which can be automated, the use of a database has been made default and the property is marked as its own creation and marked in the reader only for reading. Do not put these dates on the form so that when you post the page, they are not set in the unit. It works for "create date" etc. For the revision date, do something similar, but there is a value generated by the update trigger rather than the default on the update.

  • For bullion (which is a false default): In addition to verifying an entity, besides an attempted value for the field, besides verifying the entity. Alternatively, you can make the column blank and check that it is not empty, both are compromising, but later the data model verification frame is fit, so I pre preferred.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -