MVC Model Preserve information on pass back to controller

A model consist of X properties.  (Say 5 string variables.)  
The strongly typed view displays 2 of the 5 properties but does not have an html element for the other 3 properties.  When the view post back the method “UpdateModel()”, works as expected, both string1 and string2 have values.  

Is there a graceful way to preserve the other 3 values?  Do I have to put them in a hidden element?  Do I have to put them in a ViewBag and copy them back one by one?

  public ActionResult Index()
     var mMode = new myModel();
    //All 5 strings filled with data.
    return View(mMode);

public ActionResult ButtonToCallNoParms()
     var myModelTest = new myModel();
     UpdateModel(myModelTest);  <<how to get the other three properties not used by view?
     return RedirectToAction("index");

@model ModelUpdateInTempForm.Models.myModel
<form action="/TestTempData/ButtonToCallNoParms" method="post">
@Html.TextBoxFor(m => m.string1);
@Html.TextBoxFor(m => m.string2);
     <input type="submit" value="Text of submit button" />

P.S. This is for a year end process and I do not care about performance, I would like to generically save all that is added to the model for the redirect.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Roopesh ReddyIT AnalystCommented:

I think  if you set the default values of the properties, then it will retain the same after the post back, if those are not updated from the View!

Did you check this scenario?
wilfordrocksAuthor Commented:
Yes, properties not used by the view are not returned by the UpDateMode().
Roopesh ReddyIT AnalystCommented:

Then you can add few hidden variables on the page and update them back!

Also, you can store those in Session and retrieve them back!

Hope it helps u...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Is there a graceful way to preserve the other 3 values?  

There are a few ways.

Do I have to put them in a hidden element?  

Yes, that is one way that gives you a lot of control over whats retained and whats not. Its a graceful way, nothing wrong about it. In fact, this may be the best solution given that some of the fields are visible and others not.

Another solution, that's generic enough, is to serialize the whole model as JSON and then use client side scripting to post back as a form, but this is more suited to scenarios where you want the entire model be posted back invisibly and generically (the same piece of code works for different models), or where the models are large enough to justify the overhead.

Nonetheless, you can still combine it with some client side code that uses that JSONified model and merges user changes (UI changes) into it and posts it back.

Do I have to put them in a ViewBag and copy them back one by one?

ViewBag is for the scope of a request and is not persisted across requests. You can either use Session (server side, not graceful IMO) or have the client resend.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.