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 7966395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:24:53+00:00 2026-06-04T06:24:53+00:00

I am using remote validation to check the availability of username during registration for

  • 0

I am using remote validation to check the availability of username during registration for my asp.net mvc 3 applicaion (C#).

I am using MVC remote Attribute validation as:

[Remote("IsUserNameAvailable", "User")]
public string UserName { get; set; }

When I return this:

return Json(true, JsonRequestBehavior.AllowGet);

Then I want to perform something like set the hidden field value, which is return from action or show green icon image. And i want to also return ID with true.

How to achieve this things ?

In short, I want to do something on success.

  • 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-06-04T06:24:55+00:00Added an answer on June 4, 2026 at 6:24 am

    One way to achieve that is to add a custom HTTP response header from the validation action:

    public ActionResult IsUserNameAvailable(string username)
    {
        if (IsValid(username))
        {
            // add the id that you want to communicate to the client
            // in case of validation success as a custom HTTP header
            Response.AddHeader("X-ID", "123");
            return Json(true, JsonRequestBehavior.AllowGet);
        }
    
        return Json("The username is invalid", JsonRequestBehavior.AllowGet);
    }
    

    Now on the client we obviously have a standard form and an input field for the username:

    @model MyViewModel
    @using (Html.BeginForm())
    {
        @Html.EditorFor(x => x.UserName)
        @Html.ValidationMessageFor(x => x.UserName)
        <button type="submit">OK</button>
    }
    

    and now the last piece of the puzzle is to attach a complete handler to the remote rule on the username field:

    $(function () {
        $('#UserName').rules().remote.complete = function (xhr) {
            if (xhr.status == 200 && xhr.responseText === 'true') {
                // validation succeeded => we fetch the id that
                // was sent from the server
                var id = xhr.getResponseHeader('X-ID');
    
                // and of course we do something useful with this id
                alert(id);
            }
        };
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am using validation jQuery plugin and its remote option for check whether user
I'm using the current version of ASP.net MVC to display a form. Validation is
Using asp.net MVC3, I have a partial view which requires remote validation. As I
I have a form in which I am using remote validation to check if
I am developing an ASP.NET MVC app and I've been looking into using Data
I am using remote validation to make sure that the email and username fields
I use the jQuery Validation plugin for validation using remote: /valid_password.json to check on
How to send CTRL+C/SIGINT to a remote host using Net::Ping in Perl ? I'm
I'm using the jquery validation control remote method to test if an email address
Using the built in remote method in jQuery Validation , I can refer to

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.