Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6357829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:14:50+00:00 2026-05-24T23:14:50+00:00

I have created custom validation attribute [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited =

  • 0

I have created custom validation attribute

[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
    public sealed class ValidateDublicateNameAttribute : ValidationAttribute, IClientValidatable
    {
        private const string _defaultErrorMessage = "Library with title {0} is already exist";
        private UnitOfWork unit = new UnitOfWork();

        public ValidateDublicateNameAttribute()
            : base(_defaultErrorMessage)
        {
        }
        public override s

tring FormatErrorMessage(string name)
{
return String.Format(ErrorMessageString, name);
}

    protected override ValidationResult IsValid(object value, ValidationContext validationContext)
    {
        string valueAsString = value as string;
        ValidationResult result = ValidationResult.Success;
        if (String.IsNullOrEmpty(valueAsString))
        {
            if (unit.ResourceSrvc.GetLibraryByTitle(valueAsString) != null)
            {
                result = new ValidationResult(String.Format(_defaultErrorMessage,value));
            }
        }
        else
        {
            result = new ValidationResult("Title cant be empty or null");
        }
        return result;
    }

    public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
    {
        var rule = new ModelClientValidationRule
        {
            ErrorMessage = this.ErrorMessage,
            ValidationType = "dublicatename",
        };
        yield return rule;
    }
}

and have decorated my model using it

public class ResourceLibraryModel
{
    public Guid LibraryId { get; set; }
    [Required]
    [ValidateDublicateName(ErrorMessage="title cant dublicate")]
    public string Title { get; set; }
}

in client side I have

<script src="/Scripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {

        $.validator.addMethod("dublicatename", function (value, element, params) {
            alert("test");
        });

    });
</script>

I have not any validation parameters and didn’t write $.validator.unobtrusive.adapters.add(….)

Server side validation works perfectly, but client side does not work.

Any ideas?

and this is view

     @using (Ajax.BeginForm("CreateLibrary", "Resource", new AjaxOptions { OnSuccess = "RequestSucceeded"}))
        {
            @Html.ValidationSummary(true, "Account creation was unsuccessful. Please correct the errors and try again.")
                <div>
                    @*<div style="margin-bottom:15px">
                        <label><b>Library information:</b></label>
                    </div>*@

                    <div class="editor-field">
                        @Html.TextBoxFor(m => m.Title, new { @class = "logon-field" })
                        @Html.ValidationMessageFor(m => m.Title)
                    </div>
                    <div class="editor-label">
                        @Html.LabelFor(m => m.Title)
                    </div>
                 </div>
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:14:50+00:00Added an answer on May 24, 2026 at 11:14 pm

    I think the problem is that jquery.validate.min.js must be loaded after your javascript code…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a Custom Validation Attribute: public sealed class DateAttribute : DataTypeAttribute {
I have created a custom validation attribute by subclassing ValidationAttribute. The attribute is applied
I have created the following custom attribute to assist me with validating a required
I have created a custom date_Select field using 3 separate select fields: <%= f.select
Created a custom validation attribute and I would like to get it to work
I have created my own custom ValidationAttribute : public class UrlValidationAttribute : ValidationAttribute {
I have created custom MembershipUser, MembershipProvider and RolePrivoder classes. These all work and I
friends, i have created custom title bar using following titlebar.xml file with code <?xml
I have created a custom dialog for Visual Studio Setup Project using the steps
If have created a custom role within SqlServer which I added to the db__denydatareader

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.