c# - ASP MVC Radiobutton from model in list -


i want show list of radiobuttons model using entity framework , mvc 5. list displayed radiobuttons, value of radiobuttons te same al rows , can't find fault in code. perhaps here have idea?

code:

model:

public class resultindexmodel {     public ilist<resultinsertmodel> resultlist { get; set; } }  public enum beoordeling {     voldoende,      onvoldoende } public class resultinsertmodel {     public int userid { get; set; }     public int examid { get; set; }     public int id { get; set; }     public beoordeling issufficient { get; set; }     public nullable<decimal> result { get; set; }      public exam exam { get; set; }     public user user { get; set; }  } 

examscontroller:

[authorize] public actionresult addresults(int? id) {   if (id == null)   {      return new httpstatuscoderesult(httpstatuscode.badrequest);   }    viewbag.examname = examcatalog.getname(id);    return view(examcatalog.getexamstudents(id)); }  [authorize]    [httppost]    [validateantiforgerytoken]         public actionresult addresults([bind(include = "id,result")] list<resultinsertmodel> model)         {             int examid = 0;             if (modelstate.isvalid)             {                 foreach (var in model)                 {                     var c = db.examsubscription.where(a => a.id == i.id).firstordefault();                     var e = db.exam.where(a => a.id == c.examid).firstordefault();                      if (c != null)                     {                         if (!e.resultisdecimal)                         {                             if (i.issufficient == beoordeling.voldoende)                             { //issufficient have same value beoordelig.voldoende ?)                                 //voldoende                                 c.result = 10;                             }                             else                             {                                 //onvoldoende                                 c.result = 1;                             }                         }                         else                         {                             c.result = i.result;                         }                     }                      examid = c.examid;                 }                  //db.entry(sub).state = entitystate.modified;                 db.savechanges();                  //resultsentered vullen op examen                 var exam = db.exam.where(a => a.id == examid).firstordefault();                  if (exam.resultsentered == null)                 {                     exam.resultsentered = system.datetime.now;                      db.entry(exam).state = entitystate.modified;                     db.savechanges();                 }               }             return redirecttoaction("results", new { id = examid });         } 

view:

@html.radiobuttonfor(model => model[i].issufficient, beoordeling.voldoende, new { @checked = "checked", id = "voldoende" + })                         @html.label("voldoende" + i, "voldoende")                         @html.radiobuttonfor(model => model[i].issufficient, beoordeling.onvoldoende, new { id = "onvoldoende" + i})                         @html.label("onvoldoende" + i, "onvoldoende") 

output html:

<input checked="checked" data-val="true" data-val-required="het veld issufficient vereist." id="voldoende0" name="[0].issufficient" type="radio" value="voldoende" /> <label for="voldoende0">voldoende</label> <input id="onvoldoende0" name="[0].issufficient" type="radio" value="onvoldoende" /> <label for="onvoldoende0">onvoldoende</label> 

as can see in comment in controller, issufficient have value 'beoordeling.voldoende'. can me?

i have found solution. instead of radionbuttonfor(issufficient) use result. don't if solution, works!


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -