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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:50:43+00:00 2026-05-26T04:50:43+00:00

Basically put, I have an action that saves a form to a database, then

  • 0

Basically put, I have an action that saves a form to a database, then redirects the user to a list. From this list, the user can select a few actions.

One of these actions is essential and I would like the user to be passes directly to this straight after creating an object, however, as the ID of the first object does not exist yet, I am not sure how to pass the ID through.

For example Currently –

            //Excerpt  
            db.form.Add(ViewModel);
            db.SaveChanges();
            return RedirectToAction("List");

Then I have a list that is pulled in the normal way, and there is a link that the user can click to go to /stage2/(id).

What I would ideally like is to change my code to something like:

            //Excerpt  
            db.form.Add(ViewModel);
            var newentry = db.SaveChanges();
            return RedirectToAction("Stage2", new {id = newentry));

I have seen that calling SaveChanges() in this manner results an int being returned, but, I have tried and it doesn’t seem to pull the ID of the object, I have tried a few other things but am unsure of the syntax to use.

All I can think is to detach the object, then select it again and return, but, is there a more “slick” or direct way of doing this?



EDIT – I think I have worked this out… but, I need to wait 7 hours until I can post an answer.

Unless I am mistaken – in which case, please can someone tell me!… It looks like that Entity Framework automatically updates the object that you pass it.

When I pass it a form object, upon calling SaveChanges, it automatically sets the ID of the form object.

So, all I needed was:

        //Excerpt  
        db.form.Add(ViewModel);
        return RedirectToAction("Stage2", new {id = ViewModel.id));
  • 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-05-26T04:50:44+00:00Added an answer on May 26, 2026 at 4:50 am

    Unless I am mistaken – in which case, please can someone tell me!… It looks like that Entity Framework automatically updates the object that you pass it.

    When I pass it a form object, upon calling SaveChanges, it automatically sets the ID of the form object.

    So, all I needed was:

        //Excerpt  
        db.form.Add(ViewModel);
        return RedirectToAction("Stage2", new {id = ViewModel.id));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an HttpModule that I have put together from cobbling a couple of
I've tried searching for this but it's pretty difficult to put into words. Basically,
I have an MVC app that is basically one page with a bunch of
I have an XML file that I have parsed and have put the information
I have a WPF app that from time to time needs to perform a
I basically need to show a wait window to the user. For this i
Greetings: I have put together a RESTful web service in .NET 3.5 that takes
Basically whats happening is I can create a new item that gets saved to
I have basically the following setup in my package: thing.py: from otherthing import *
EDIT: If you can't be bothered to read this mammoth question, I've put a

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.