c# - Why won't the data in the model persist? -


i have model, myviewmodel, members (not included).

namespace anamespace {     public class myviewmodel     {        public int id { get; set }        public edittableobject edittable { get; set }        public list<edittableobject> edittables { get; set }        // other members     }      public class edittableobject     {        public int id { get; set }        // other members     } } 

in controller there 2 actionresult index() methods

in first, index(int? id), assign value model.id , add edittableobjects edittables list.

then, in second, index(viewmodel tmpmodel), trying use members gave values in first index method. however, id member not contain value assigned it; it's null. strangely, edittables list contain values assigned it.

here code controller:

namespace anothernamespace {    public class mycontroller    {       public actionresult index(int? id)       {          if (id != null)          {             model.id = (int)id;          }          else          {             model.id = 1000;          }            model.edittable = new edittableobject();           model.edittable.id = model.id;           model.edittables.add(model.edittable);           return view(model);       }        public actionresult(myviewmodel tmpmodel)       {          return redirecttoaction("index", new { id = tmpmodel.id });       }    }  } 

if set break point on second index method find edittables data persists not model.id data.

why edittables data persisting not model.id data?

thanks suggestions.

eventhough don't quite question (posting code doesn't work highly improve chances of getting answer) i'll give shot.

httprequests stateless. between calls different methods need persist data. that's been done using database.

this source started mvc: http://www.asp.net/mvc


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -