asp.net mvc - How to display labels and textboxes with the help of model properties in MVC5 razor view with html helpers? -


i not able create labels , textboxes using model in view html helpers.

my view syntax:

  @using (ajax.beginform("roomsavail",new ajaxoptions                                 {                                   updatetargetid = "roomsavaildata",                                   insertionmode ="insertionmode.replace"                                 }))                                                                                                               {     <input type='text' id="checkin" class="form-control datepicker" />     <input type='text' id="checkout" class="form-control datepicker" />     <button type="submit" value="search"></button>  } @model ienumerable<roomavailabilitysummary>  <div>      @html.labelfor(model=>model.arrdat)  </div>  <div>      @html.editorfor(model=>model.name)  </div> 

my model

public class roomavailabilitysummary {    public string arrdat{get;set;}    public string name{get;set;} } 

after doing this, view not rendering model properties view display text labels , getting error "syste.collection.generic.ienumerable not contain definiton arrdat"

why not able render model property in html helper display name of html helper?

and want access model values in controller. how can this?

your model is:

@model ienumerable<roomavailabilitysummary> 

and trying access name in ienumerable:

 <div>      @html.editorfor(model=>model.name)  </div> 

you should use foreach if ienumerable or @model roomavailabilitysummary if not ienumerable

added:

something should work:

@model ienumerable<roomavailabilitysummary>  @if(model.count() > 0) {  <div>      @html.labelfor(model=>model.first().name)  </div> }  @foreach (var item in model) {  <div>      @html.editorfor(model=>item.name)  </div> } 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -