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

  • Home
  • SEARCH
  • 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 3312830
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:02:33+00:00 2026-05-17T22:02:33+00:00

I currently have a method in my controller which accepts a form collection, saves

  • 0

I currently have a method in my controller which accepts a form collection, saves the data, and then displays the data in a ‘Details’ page. At the moment, the code currently looks something like:

[HttpPost]
public ActionResult Create(PersonModel person)
{
    if (person.IsValid())
    {
        person.additionalData = "Person created successfully";
        return View("Details", person);
    }
}

The problem is that returning the Details view in this manner retains the URL mysite/Person/Create – ideally I would like the URL to be mysite/Person/Details/{PersonId}.

Im sure this must be possible. Obviously, I could use Response.Redirect, however this doesn’t allow me to pass the model to the view. As far as I can tell, I can’t pass the model using RedirectToAction?

Thanks for the help.

EDIT: To confirm – the model produced by the Create action is different to the default one created by the Details action. Therefore, doing a straight redirect to Action and passing the Id does not work as the model produced is not correct. To give more context, the model from the Create action contains an additional value saying ‘Person created successfully’, if I redirect to the Details action, this message is not present in the model.

  • 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-17T22:02:33+00:00Added an answer on May 17, 2026 at 10:02 pm

    Straight from my own app:

    public ActionResult Create(Booking item)
    {
        if (ModelState.IsValid)
        {
            int newID = _tasks.Create(item);
            // NEW section to emulate model being populated for use in Details view
            TempData["additionalData"] = "Person created successfully";
            return RedirectToAction("Details", new { id = newID });
        }
        else
        {
            return View();
        }
    }
    

    then, couldn’t your “Details” action be like this:

    public ActionResult Details(int id)
    {
        var item = _tasks.GetByKey(id);
        var additionalData = TempData["additionalData"];
        if(item != null) {
            if(additonalMessage!=null)
            {
                item.additionalData = additionalData;
            }
            return View(item);
        }
        else
            return View("Notfound");
    }
    

    couldn’t you adopt a similar approach??

    You could just do the redirect as per convention and have a flag set (on tempdata as above) that gives this message? The tempadata flag would ONLY be set inside the Create action, therefore would only ever happen on Creating a new ‘person’ object. thus the Details action would only ever show it as a consequence of the Create action

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a controller method that returns a JsonResult: public JsonResult EditField(int FieldID,
Currently i have this method: static boolean checkDecimalPlaces(double d, int decimalPlaces){ if (d==0) return
Currently, I don't really have a good method of debugging JavaScript in Internet Explorer and
In my controller i have an action which does not have a corresponding view.
Problem, there's no method: bool ChangePassword(string newPassword); You have to know the current password
I currently have an MS Access application that connects to a PostgreSQL database via
I currently have speakers set up both in my office and in my living
I currently have an existing database and I am using the LINQtoSQL generator tool
We currently have a company email server with Exchange, and a bulk email processing
I currently have a fairly robust server-side validation system in place, but I'm looking

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.