MVC web form to use different models to load and save data

Posted on 2012-08-10
Last Modified: 2012-08-13
I am setting up a web form in an ASP.NET MVC web app. A user logs in using LDAP credentials. Once they log in,  I would like to query an existing database to prepopulate  the form with some info that we may or may not already have. When they complete the form I would like to save the data to a new database. I have done forms before where you start with an empty form and save to a new database, but am trying to add the step of pulling existing data from a separate database to fill in as much info for the user as we can. As an example, the user logs in with their username. The existing database contains username, so I can query it to get Name, Address and Phone. I would like to put that into the form for the user. The user can then complete the form and save. The saved date will go to a separate database.
Question by:hwsitservices
    LVL 21

    Accepted Solution

    I'm not sure what the actual question is here, but at a high level you should query the existing database to get the data, fill in a model that you pass to the MVC View, and use the model to populate the form. When the form posts back you'll get back the model and you can take the data and save it to the other database.
    public ActionResult Index()
        ViewModel vm = new ViewModel();
        // read existing data
        vm.Name = existingName;
        return View( vm );
    public ActionResult Index( ViewModel vm )
        // save data from vm into new database

    Open in new window


    Author Closing Comment

    Thank you, that is what i was looking for

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now