locked
How to create label text using html helper from Model in ASP.Net MVC 5 (Razor View) RRS feed

  • Question

  • User1711816688 posted

    I am trying to create a label text using html helper from my model RoomAvailabilitySummary

    View Design:

    @model IEnumerable<WBE.Model.RoomAvailabilitySummary>
    
    @using(Ajax.BeginForm("RoomsAvail", new AjaxOptions
                                           {
                                            UpdateTargetId = "RoomsAvailData",
                                            InsertionMode = InsertionMode.Replace
                                           }))
    {
     @Html.AntiForgeryToken()
     <div class="container paddingzero">
        <div class="row rowbackground">
            @Html.DisplayFor(model => model.ARRDAT)
        </div>
        <div class="row rowbackground">
            @Html.EditorFor(model => model.ARRDAT)
        </div>
        <div class="row rowbackground">
            @Html.DisplayFor(model => model.DEPDAT)
        </div>
        <div class="row rowbackground">
            @Html.EditorFor(model => model.DEPDAT)
        </div>
     </div>
    }
    <div class="tab-content" id="RoomsAvailData">
        @Html.Partial("_AvailableRoomsandPackages", Model);
    </div>
    

    Controller:

    public class RoomAvailabilitySummary
    {
        [Key]
        public int CUSTCODE { get; set; }
        [Display(Name = "Checkin")]
        public string ARRDAT { get; set; }
        [Display(Name = "Check out")]
        public string DEPDAT { get; set; }
    }
    

    Problem: I am unable to create label text using my model with html helper.

    Error i am getting: IEnumerable' does not contain a definition for 'ARRDAT' and no extension method 'ARRDAT' accepting a first argument of type IEnumerable

    What i have done the mistake in my code?

    Monday, April 14, 2014 7:39 AM

Answers

  • User-417640953 posted

    @model IEnumerable<WBE.Model.RoomAvailabilitySummary>

    Error i am getting: IEnumerable' does not contain a definition for 'ARRDAT' and no extension method 'ARRDAT' accepting a first argument of type IEnumerable

    Hi Mallikharjun,

    Thank you post the issue to our forum.

    Based on your description, I see want to show the IEnumerable model to your view. Please note that the model you used is the

    IEnumerable<WBE.Model.RoomAvailabilitySummary> type not the WBE.Model.RoomAvailabilitySummary type. Please use the foreach in your view like below.

    @using(Ajax.BeginForm("RoomsAvail", new AjaxOptions
                                           {
                                            UpdateTargetId = "RoomsAvailData",
                                            InsertionMode = InsertionMode.Replace
                                           }))
    {
     @Html.AntiForgeryToken()
      @foreach(var item in Model){
      <div class="container paddingzero">
        <div class="row rowbackground">
            @Html.DisplayFor(item => item.ARRDAT)
        </div>
        <div class="row rowbackground">
            @Html.EditorFor(item  => item.ARRDAT)
        </div>
        <div class="row rowbackground">
            @Html.DisplayFor(item  => item.DEPDAT)
        </div>
        <div class="row rowbackground">
            @Html.EditorFor(item => item.DEPDAT)
        </div>
      </div>
      }
    }
    

    Thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 15, 2014 1:11 AM