Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

fixed the whole error if could please because l am not able how to crate Custom Data Validtion as below using System; using System.Collections.Generic; using

fixed the whole error if could please because l am not able how to crate Custom Data Validtion as below

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.ComponentModel.DataAnnotations;

namespace StudentEnrollment.Models { public class InvalidChars: ValidationAttribute { public InvalidChars(char invalidNotes) :base("{0} Notes contanis unacceptable charaters") { _invalidNotes = invalidNotes; }

protected override ValidationResult IsValid( object value, ValidationContext validationContext) { if (value != null) { var valueAsString = value.ToString(); if (valueAsString.Split(' ').Length > _invalidNotes) { var errorMessage = FormatErrorMessage(validationContext.DisplayName); return new ValidationResult(errorMessage); } } return ValidationResult.Success; }

private readonly char _invalidNotes; } }

this picutre whare class on inside the model as

image text in transcribed

the inrollemnt file as below with all classes

using System; using System.Collections.Generic; using System.Linq; using System.Web;using System.ComponentModel.DataAnnotations;

namespace StudentEnrollment.Models { public class Enrollment { public virtual int EnrollmentId { get; set; }

[Display(Name = "Student ID")] public virtual int StudentId { get; set; } public virtual Student Student { get; set; }

[Display(Name = "Course ID")] public virtual int CourseId { get; set; }

public virtual Course Course { get; set; }

[Display(Name = "Grade")] [RegularExpression("^[A-F]{1}$", ErrorMessage = "Enter value A , B, C, D, E, F")] public virtual string Grade { get; set; }

public virtual bool IsActive { get; set; }

[Display(Name = "Assigned Campus")] [Required(ErrorMessage = "Enter value for campus")] public virtual string AssignedCampus { get; set; }

[Display(Name = "Enrolled in Semester")] [Required(ErrorMessage = "Enter enrollment semester")] public virtual string EnrollmentSemester { get; set; }

[Display(Name = "Enrollment Year")] [Required(ErrorMessage = "Enter value for Enrollment Year ")] [Range(2018, 2020, ErrorMessage = "Enter value greater than 2018")] public virtual int EnrollmentYear { get; set; }

[InvalidChars("^[A-F]{1}$)"] public virtual string Notes { get; set; } } }

this the question requremnts as

1. Add a new field called Notes (type is String). Add this field to the Bindings and also to your views. Make sure you do code migration also after you add the field. 2. Create custom data validation attribute called InvalidChars

3. The custom data validation attribute should have a default error message as Notes contains unacceptable characters! 4. User must be able to provide a list of characters that can be considered invalid and an error message as shown in video. If user does not provide error message, default error message should show. 5. Test your changes and attach screenshots

l did all the binding and add the field to views but could you plase fixs the issues based on the question as char because l am not able to to convert string to char and thank you

solution"EnrollementApplication' (2 projects) D EnrollementApplication.Tests (unavailable) StudentEnrollment Cp Connected Services Properties References App-Data DApp Start Content DControllers Dfonts D Migrations Models c# Course.cs c# Enrollment.cs # EnrollmentDbContext.cs # InvalidChars.cs # Student.cs Samples DScripts Views ApplicationInsights.config favicon.ico Global.asax solution"EnrollementApplication' (2 projects) D EnrollementApplication.Tests (unavailable) StudentEnrollment Cp Connected Services Properties References App-Data DApp Start Content DControllers Dfonts D Migrations Models c# Course.cs c# Enrollment.cs # EnrollmentDbContext.cs # InvalidChars.cs # Student.cs Samples DScripts Views ApplicationInsights.config favicon.ico Global.asax

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MongoDB Applied Design Patterns Practical Use Cases With The Leading NoSQL Database

Authors: Rick Copeland

1st Edition

1449340040, 978-1449340049

More Books

Students also viewed these Databases questions

Question

What is a surveillance log?

Answered: 1 week ago

Question

21 19.2 25

Answered: 1 week ago

Question

Compare the current team to the ideal team.

Answered: 1 week ago

Question

a. Do team members trust each other?

Answered: 1 week ago