asp.net mvc - "Create" View for parent-child relationship MVC 4 -


so have model:

 public class subthing  {      public virtual int subthingid { get; set; }      public virtual int thingid { get; set; }       public virtual string name { get; set; }       public virtual int parentid { get; set; }      public virtual subthing parent { get; set; }      public virtual list<subthing> childs { get; set; }       public virtual thing thing{ get; set; } } 

and want make create view introducing subthings related subthings. have controller:

public actionresult criarmoresubthings(int id)         {              var x = db.subthings.firstordefault(e => e.subthingid == id);              if (x == null)             {                 return httpnotfound();             }              var subthing = new subthing()             {                 thingid = x.thingid,                 parentid = id //(also tried x.subthingid)             };              return view("criarmoresubthings", subthing);         }          [httppost]         [validateantiforgerytoken]         public actionresult criarmoresubthings(subthing subthing)         {             if (modelstate.isvalid)             {                 db.subthings.add(subthing);                 db.savechanges();                               return redirecttoaction(blabla);             }              return view(subthing);         } 

but create parentid = 0, parentid should subthing id. (for record, can wrong, searched lot can't make work, novice here). doing wrong? thanks


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -