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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:52:51+00:00 2026-06-08T19:52:51+00:00

I have a field for a ZIP Code. I want that, when the person

  • 0

I have a field for a ZIP Code.
I want that, when the person fills this field with a zip code and click in another field, triggers a event (onBlur).
This Event will execute a select in database and get the address and fill the other fields with this information.
I read that is not a good idea execute a Controller Method from the View.
So, how can I develop this?

My zip code field:

<div class="editor-field">
    @Html.Label("ZIP CODE")
    @Html.Editor("zipCodeClient")
</div>

Thanks!

  • 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-08T19:52:53+00:00Added an answer on June 8, 2026 at 7:52 pm

    If you have access to jQuery I would use it’s ajax function to call a wcf web service that returns the relevant address information in a JSON format. Otherwise, you could create your own XHR request and parse the response.

    $('#zipCodeClient').blur(function() {
        var zipCode = $(this).val();
        if(zipCode.length >= 5 && zipCode.length <= 10) {
            $.ajax({
                type: 'GET',
                data: { ZipCode: zipCode },
                url: 'something/ZipCodeToAddressService',
                dataType: 'json',
                contentType:  'application/json; charset=utf-8',
                success: function(data) {
                   var responseObject = jQuery.parseJSON(data);
                   $('#cityTextBox').val(responseObject.City);
                   $('#stateTextBox').val(responseObject.State);
                }
            });
        }
        else {
            // zip code not valid
        }
    });
    

    In WCF:

    [ServiceContract()]
    public interface IAddressServices
    {
        [OperationContract()]
        [WebGet(ResponseFormat = WebMessageFormat.Json)]
        string ZipCodeToAddressService(string ZipCode);
    }
    
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple)]
    public class AddressServices : IAddressServices
    {
        public string ZipCodeToAddressService(string ZipCode)
        {
            using (SqlConnection sqlConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["DB"].ConnectionString))
            {
                using (SqlCommand sqlCmd = new SqlCommand("ZipCodeToAddressStoredProc", sqlConnection))
                {
                    sqlCmd.CommandType = CommandType.StoredProcedure;
                    sqlCmd.Parameters.Add("@Zip", SqlDbType.NVarChar).Value = ZipCode;
                    sqlConnection.Open();
                    SqlDataReader sDR = sqlCmd.ExecuteReader(CommandBehavior.CloseConnection);
                    DataTable tbl = new DataTable();
                    tbl.Load(sDR);
                    sDR.Close();
                    var citystateData = from DataRow Row in tbl.AsEnumerable()
                                       select new
                                       {
                                          City = Row.Field<string>("City"),
                                          State = Row.Field<string>("State")
                                       };
                    JavaScriptSerializer js = new JavaScriptSerializer();
                    StringBuilder sb = new StringBuilder();
                    js.Serialize(cityStateData, sb);
                    string rtrnCityStateData = sb.ToString();
                    return rtrnCityStateData;
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have field that it's not a key (it's text) and I want to
I have field like a_b_c_d I want as the output a b c_d, this
I have a very basic question. I want to retrieve a zip code automatically
I have a field where user inputs Zip code. Based on the value entered
i have a usertable which includes a field named zip (postal code) I also
I have field X that contains text with spaces in the end of the
In my class, I have field int count . I want to create a
I have a zip table and a city table. Thereby a zip code can
I have a simple address book app that I want to make searchable. The
I have a zipcode field in a database that I just took over. Previously,

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.