Social Media And Global Computing Managing MVC with Model Validation

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

CSCI 6962: Server-side Design and Programming Input Validation and Error Handling.
Composition CMSC 202. Code Reuse Effective software development relies on reusing existing code. Code reuse must be more than just copying code and changing.
Introduction to MVC Action Methods, Edit View, and a Search Feature NTPCUG Dr. Tom Perkins.
Evan Korth New York University Computer Science I Classes and Objects Professor: Evan Korth New York University.
Creating a Blank Database 1. Open up Microsoft Access 2. Click on Blank document button 3. On the right panel, Specify the location for saving your database.
Database Design Concepts Info 1408 Lecture 2 An Introduction to Data Storage.
Database Design Concepts INFO1408 Term 2 week 1 Data validation and Referential integrity.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Database Design Concepts Info 1408 Lecture 2 An Introduction to Data Storage.
Microsoft Access 2000 Creating Tables and Relationships.
Part 06 – A More Complex Data Model Entity Framework and MVC NTPCUG Tom Perkins.
PHP meets MySQL.
 A database is a collection of data that is organized so that its contents can easily be accessed, managed, and updated. What is Database?
Mastering Char to ASCII AND DOING MORE RELATED STRING MANIPULATION Why VB.Net ?  The Language resembles Pseudocode - good for teaching and learning fundamentals.
SIMULATED UNIX FILE SYSTEM Implementation in C Tarek Youssef Bipanjit Sihra.
Using the selection structure (Unit 7) Visual Basic for Applications.
Introduction to ASP.NET MVC Information for this presentation was taken from Pluralsight Building Applications with ASP.NET MVC 4.
Chapter 8 Cookies And Security JavaScript, Third Edition.
C# Tutorial -1 ASP.NET Web Application with Visual Studio 2005.
Microsoft Visual Basic 2005 CHAPTER 7 Creating Web Applications.
Copyrighted material John Tullis 10/17/2015 page 1 04/15/00 XML Part 3 John Tullis DePaul Instructor
Unit 8.3 Learning Objectives Insert users into the ASP.NET Membership system from code Capture data being sent to the database Capture Exceptions that.
Senior Elective Tutorial MS Access Database: Student Records.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 25.1 Test-Driving the ATM Application 25.2.
Lesson 13 Databases Unit 2—Using the Computer. Computer Concepts BASICS - 22 Objectives Define the purpose and function of database software. Identify.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Vijayalakshmi G M Validation Controls.
Programming with Microsoft Visual Basic 2008 Fourth Edition Chapter Eight String Manipulation.
BIT 286: Web Applications Lecture 04 : Thursday, January 15, 2015 ASP.Net MVC -
Modify Tables and FieldsModify Tables and Fields Lesson 4 © 2014, John Wiley & Sons, Inc.Microsoft Official Academic Course, Microsoft Word Microsoft.
6 Copyright © 2004, Oracle. All rights reserved. Adding Custom Validation.
1 Once you log in – How to create your profile Company Name TID Contact Name - Enter your name using the format First Name space Last Name User ID – will.
Beginning ASP.NET in C# and VB Chapter 9
BIT 286: Web Applications Lecture 04 : Thursday, January 15, 2015 ASP.Net MVC -
Presented by Alexey Vedishchev Developing Web-applications with Grails framework American University of Nigeria, 2016 Form Submission And Saving Data To.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 11 Creating Web Applications and Writing Data to a Database.
ASP.NET Programming with C# and SQL Server First Edition
Creating a database table
Unit 9.1 Learning Objectives Data Access in Code
EF Relations Object Composition
CONTENT MANAGEMENT SYSTEM CSIR-NISCAIR, New Delhi
MIS Professor Sandvig MIS 324 Professor Sandvig
GCSE COMPUTER SCIENCE Practical Programming using Python
Chapter 5: The Art of Ensuring Integrity
ASP.NET Razor Engine SoftUni Team ASP.NET MVC Introduction
Instructor Materials Chapter 5: The Art of Ensuring Integrity
Road Map Introduction to object oriented programming. Classes
Data File Import / Export
Working with Forms and Regular Expressions
Adding and editing students and student test settings
Social Media And Global Computing Managing MVC with Model Validation
MIS Professor Sandvig MIS 324 Professor Sandvig
Adding and editing users
CIS 136 Building Mobile Apps
Variables ICS2O.
Adding and Editing Users
String Methods: length substring
Access Lesson 2 Creating a Database
MIS Professor Sandvig MIS 324 Professor Sandvig
Customizing Views Views Customize කර ගැනීම
Creating and Configuring Models Models create කිරීම සහ config කර ගැනීම
Instructor Materials Chapter 5: The Art of Ensuring Integrity
Database Design and Development
This is the Sign In page for the Dashboard
05 | Customizing Views Jon Galloway | Development Platform Evangelist
Designs for Data Integrity, validations, security and controls
Tazin Afrin October 24, 2013 Day 19: Access Chapter 4 Tazin Afrin October 24, 2013.
Instructor Materials Chapter 5: Ensuring Integrity
Presentation transcript:

Social Media And Global Computing Managing MVC with Model Validation

Validation Attributes Common Validation Attributes for Model Properties (which optionally can use an ErrorMessage parameter): Range [Range(0,30)] [Range(0,30,ErrorMessage = "Must be in range from 0 to 30")] Required [Required()] [Required(ErrorMessage = "This field is required")] StringLength [StringLength(50)] [StringLength(50, MinimumLength=5, ErrorMessage = "Length must be between 5 and 50 characters")]

Validation Attributes The EmailAddress Attribute is used to determine if an email address has a valid format, which consist of three parts: the uname, the @ sign, and the domain name. So “john@gmail.com” is valid, but “john” is not valid, nor is “john@gmail”. EmailAddress [EmailAddress] [EmailAddress(ErrorMessage = "Invalid Email Address"]

Validation Attributes The DisplayFormat Attribute is often also needed to deal with handling empty strings when they are allowed, because an empty string field can be incorrectly saved as a null value, which is different than an empty string value: DisplayFormat [DisplayFormat(ConvertEmptyStringToNull = false)]

Validation Attributes In general, Validation Attributes are placed above Properties in program, and the DataAnnotations path needs to be declared: using System.ComponentModel.DataAnnotations; namespace MyProject.Models { public class Account [Required(ErrorMessage = "The ID Is Required")] public int ID { get; set; } [StringLength(50, ErrorMessage = "Names can’t be longer than 50 characters")] public string Name { get; set; } }

Validation Attributes When the fields of a class come from a Database, a class is created for those fields already when you created an ADO.NET Data Entity Model. Now you need to create another one if you want to add special added Validation properties.

Validation Attributes The special class is a Metadata class. It has the same name as the record in the Table, but it has the word Metadata after the name. You need to create a class with that name and then with the Metadata descriptor shown below: [MetadataType(typeof(ClassNameMetadata))] public partial class ClassName { }

Validation Attributes This is what your new class would look like: using System.ComponentModel.DataAnnotations; namespace MyProject.Models { [MetadataType(typeof(ClassNameMetadata))] public partial class ClassName } public class ClassNameMetadata [Required(ErrorMessage = "The ID Is Required")] public int ID { get; set; } [StringLength(50, ErrorMessage = "Names can’t be longer than 50 characters")] public string Name { get; set; }

ValidationSummary You can show a general summary message concerning the validation errors using the ValidationSummary HTML Helper function: When ValidationSummary is given true - @Html.ValidationSummary(true) - only Model-Level errors are shown, but if it is given false, then both Model-Level and Property Errors are shown. Model-Level errors are created in action methods with: ViewBag.ModelState.AddModelError("","The Model-Level Error Message");

ValidationSummary and ValidationMessageFor You can also give ValidationSummary a string message, and the message will show up above the Model-Level and Property-Level Errors, if there are any: @Html.ValidationSummary("There were some errors. Please correct them:“) The ValidationMessageFor HTML Helper function is used to determine which fields to manage the validation for: @Html.ValidationMessageFor(Function(model) model.ID)

Modifying A Field’s Label You can modify a label for a field using the Display Attribute. For instance, if a field name is “StreetAddress” and you want it to show as “Street Address” (with a space), you would change its label like so: [Display(Name = “Street Address")] public string StreetAddress { get; set; })