[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 341
  • Last Modified:

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

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.
0
hwsitservices
Asked:
hwsitservices
1 Solution
 
Craig WagnerSoftware ArchitectCommented:
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.
[HttpGet]
public ActionResult Index()
{
    ViewModel vm = new ViewModel();
    // read existing data
    vm.Name = existingName;
    return View( vm );
}

[HttpPost]
public ActionResult Index( ViewModel vm )
{
    // save data from vm into new database
}

Open in new window

0
 
hwsitservicesAuthor Commented:
Thank you, that is what i was looking for
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now