Hi sir,
I write custom validation in mvc, but it is not working. I shared the code for your reference. Kindly check and give me the solution for this problem.
[Note: My problem is, i cant able to see the error message, if i give fullname without space]
FullNameAttribute.cs
using System;
using System.ComponentModel.DataAnnotations;
namespace MvcApplication1.Models
{
public class FullNameAttribute : ValidationAttribute
{
public override bool IsValid(object value)
{
ErrorHandler.WriteError(value.ToString());
var nameComponents = value.ToString().Split(' ');
return nameComponents.Length == 2;
}
}
}
EmpDetails.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using MvcApplication1.Models;
namespace MvcApplication1.Models
{
public class EmpDetails
{
[Required(ErrorMessage = "Please type your name")]
[StringLength(150, ErrorMessage = "You can only add up to 150 characters")]
[FullName(ErrorMessage = "Please type your full name")]
public string From { get; set; }
}
}
With regards,
J.Prabu.
[Email:prbspark@gmail.com]