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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:07:08+00:00 2026-06-13T02:07:08+00:00

I work with c# MVC3 & razor, Entity Framework and Linq. I have a

  • 0

I work with c# MVC3 & razor, Entity Framework and Linq.

I have a form, with two field, the first one Client ID and the second one Store Name.
I would like, when the user enter the ID, then my StoreName field fill automatically… The data would come from a database where this two data are stored.

  • 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-13T02:07:09+00:00Added an answer on June 13, 2026 at 2:07 am

    You could use AJAX. So setup a controller action taking a client id as parameter and that would query your database and return the corresponding store name as JSON result. Then subscribe to the .blur event of the text input containing the store id and send an AJAX call to the controller action to fill the second input field.

    Yeah, I know, meaningless jibber-jabber, gimme the codez.

    Here:

    public ActionResult GetStoreName(int clientId)
    {
        // of course thath's just an example here. I have strictly no idea
        // what database access technology you are using, how your models look like
        // and so on. Obviously you will have to adapt this query to your data model.
        var client = db.Clients.FirstOrDefault(x => x.Id == clientId);
        if (client == null)
        {
            return HttpNotFound();
        }
    
        return Json(new { storeName = client.Store.Name }, JsonRequestBehavior.AllowGet);
    }
    

    Now assuming the following view:

    <div>
        @Html.LabelFor(x => x.ClientId)
        @Html.TextBoxFor(x => x.ClientId, new { id = "clientId", data-url = Url.Action("GetStoreName") })
    </div>
    <div>
        @Html.LabelFor(x => x.Store.Name)
        @Html.TextBoxFor(x => x.Store.Name, new { id = "storeName" })
    </div>
    

    in a separate javascript file you could subscribe to the .blur event of the first textbox, and trigger the AJAX request to the controller sending it the client id that was entered by the user. In the success callback you would update the second textfield with the result of the AJAX call:

    $(function() {
        $('#clientId').blur(function() {
            var clientId = $(this).val();
            $.ajax({
                url: $(this).data('url'),
                type: 'GET',
                cache: false,
                data: { clientId: clientId },
                success: function(result) {
                    $('#storeName').val(result.storeName);
                }
            });
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on my first MVC3 application at work (using the Razor view
I currently have two unrelated MVC3 projects hosted online. One works fine, the other
I am new to MVC3 and trying to work on my first small project
I've written a simple contact form in my mvc3 app. Everything seems to work
I'm working with MVC3, and using Entity Framework 4.0 Entities as my model. So
I'm working with Entity Framework 4.1 in an MVC3 Web Application. I am tasked
I have an MVC3 solution where I have 2 repositories & 2 service layers.
I am creating a very simple EF4 code first project with one entity. public
I am using C#, MVC3, and Razor. I have a javascript function (in the
Hi I'm having some issues understanding how MVC 3 and razor work. Basically, I

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.