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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:16:51+00:00 2026-06-12T09:16:51+00:00

So…. I have an action in my controller that basically copies the current model

  • 0

So…. I have an action in my controller that basically copies the current model and returns a new view based on that copy. To inform the user that this is a copy I append a message via the viewbag stating that it’s a copy. All seemed to be working until I noticed that it’s not the copy that is being used when rendering the new view instead it’s the original, but the viewbag on the other hand is updated so the message is shown.

Hmm, don’t know if that’s understandable so I’ll try to show what i mean with some pseudo-code as well:

Model

public class Model{
    [ScaffoldColumn(false)]
    [HiddenInput(DisplayValue = false)]
    public Guid Id { get; set; }

    public string Name { get; set; }
}

View

<input type="submit" name="Copy" value="@_("Copy")"/>

Controller

public ActionResult Copy(model) {
    ViewBag.Message = _("This is a copy.");
    var clone = model.Clone();
    return View("Index", clone);
}

I’m having a real hard time trying to wrap my head around this so any help/tips/pointers are really appreciated.

Oh, I’ve stepped through the code several times to ensure that the clone is really a clone. The only thing that differentiates them is the Id property and that is the new one in the controller but when the view renders it’s back to the old one.

  • 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-12T09:16:51+00:00Added an answer on June 12, 2026 at 9:16 am

    You need to clear the ModelState collection before returning the clone because the HtmlHelpers prefer to reuse the posted data:

    public ActionResult Copy(model) {
        ViewBag.Message = _("This is a copy.");
        var clone = model.Clone();
        ModelState.Clear();
        return View("Index", clone);
    }
    

    You can read more about this feature in this artice: ASP.NET MVC Postbacks and HtmlHelper Controls ignoring Model Changes.

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

Sidebar

Related Questions

I have an element like this: <span class=tool_tip title=The full title>The ful&#8230;</span> This seems
so I did $subject = 'sakdlfjsalfdjslfad <a href=something/8230>lol is that true?</a> lalalala'; $subject =
I have this xml <entry id=1008 section=articles> <excerpt><p>&#8230; in Richtung „Aus für Tierversuche. Kosmetik-Fertigprodukte
I see that some rss on xml have strange strings. For example, ... is
After much research, I have found that Laravel is very nice. I have a
I've got just a quick problem. I've got code that returns the last post
I have been making a wordpress template. i got stuck at some place... the
(tl;dr: see summary at the bottom.) I am implementing an application that pulls content
I have a form, one of the fields is a select field, with 5
I have a PDB file. Now it has two parts separated by TER. Before

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.