Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. pulling across value from list to display in view

pulling across value from list to display in view

Scheduled Pinned Locked Moved .NET (Core and Framework)
htmlasp-netdatabasearchitecturequestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    xnaLearner
    wrote on last edited by
    #1

    Hey Guys...so trying to get my head around MVC My Index for holiday page is linked to the model

    @model HolidayBookingApp.Models.HolidayList

    Im trying to pull the value of Holidays remaining from the HList4DD (HolidayListForDropDown) which is coming from the HolidayList.cs page. I can get it through...

    @foreach (var item in Model.HList4DD)
    {

            @Html.DisplayFor(modelItem => item.PersonId)
        
        
            @Html.DisplayFor(modelItem => item.HolidayDate)
        
        
        @Html.DisplayFor(modelItem => item.Person.HolidaysRemaining)
    

    Although this displays the holidays remaining for every holiday booked. So if 20 holidays is the limit (4 booked and 16 remaining) this will produce a list of the dates of holidays booked i.e 4 records stating which date is booked, but it will show the '16' holidays remaining 4 times as well. Yes, this is because it is inside the for loop but I tried to display it on its own and it didnt work

    @Html.DisplayFor(model => model.HList4DD.//what do i add here?

    Also tried to add

    Person person = new Person();
    currentHolidaysRemaining = person.HolidaysRemaining;

    to the HolidayList. cs then in the view do

    @Html.DisplayFor(model => model.currentHolidaysRemaining)

    but its not pulling across the correct value, just returning 0 please advise....thanks

    X D 2 Replies Last reply
    0
    • X xnaLearner

      Hey Guys...so trying to get my head around MVC My Index for holiday page is linked to the model

      @model HolidayBookingApp.Models.HolidayList

      Im trying to pull the value of Holidays remaining from the HList4DD (HolidayListForDropDown) which is coming from the HolidayList.cs page. I can get it through...

      @foreach (var item in Model.HList4DD)
      {

              @Html.DisplayFor(modelItem => item.PersonId)
          
          
              @Html.DisplayFor(modelItem => item.HolidayDate)
          
          
          @Html.DisplayFor(modelItem => item.Person.HolidaysRemaining)
      

      Although this displays the holidays remaining for every holiday booked. So if 20 holidays is the limit (4 booked and 16 remaining) this will produce a list of the dates of holidays booked i.e 4 records stating which date is booked, but it will show the '16' holidays remaining 4 times as well. Yes, this is because it is inside the for loop but I tried to display it on its own and it didnt work

      @Html.DisplayFor(model => model.HList4DD.//what do i add here?

      Also tried to add

      Person person = new Person();
      currentHolidaysRemaining = person.HolidaysRemaining;

      to the HolidayList. cs then in the view do

      @Html.DisplayFor(model => model.currentHolidaysRemaining)

      but its not pulling across the correct value, just returning 0 please advise....thanks

      X Offline
      X Offline
      xnaLearner
      wrote on last edited by
      #2

      Im now using

      bool isFirst = true;
      @int remainingHolidays = 0;

      @foreach (var item in Model.HList4DD)
      {

              @Html.DisplayFor(modelItem => item.PersonId)
          
          
              @Html.DisplayFor(modelItem => item.HolidayDate)
      

      if (isFirst)
      {
      remainingHolidays = item.Person.HolidaysRemaining;
      isFirst = false;
      }

              @Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
              @Html.ActionLink("Details", "Details", new { id = item.Id }) |
              @Html.ActionLink("Delete", "Delete", new { id = item.Id })
          
      }
          
      
      
        
      
           @\*   @Html.LabelFor(model => model.PList4DD, "Person")\*@
          
      
          
      
         
               <form action ="/Holidays/Index" id="some" method="post"> 
      
              @\* \*WORKING VERSION\*\*@ @Html.DropDownListFor(model => model.HList4DD.First().HolidayDate, new SelectList(Model.PList4DD, "Id", "Name", Model.currentPersonID), "--select--")
          
      
         <script>
             function updateFormEnabled() 
             {
                 if (verifyAdSettings()) 
                 {
                     $('#sbmt').removeAttr('disabled');
                 }
                 else 
                 {
                     $('#sbmt').attr('disabled', 'disabled');
                 }
             }
      
             function verifyAdSettings() 
             {
                 if ($('#HolidayDate').val() != '') 
                 {
                     return true;
      
                 }
                 else 
                 {
                     return false;
                 }
             }
      
      
             $('#HolidayDate').change(updateFormEnabled);         
             </script>
      
        
        @remainingHolidays.ToString()
      
                 
               <input type="submit" id= "sbmt" name="ViewHolidaysDD" value="View"/>
                </form>
      

      <script>
      $('#sbmt').attr('disabled', '');
      </script>

      the @remainingHolidays.ToString() 5 lines or so up from the bottom is saying it doesnt exist in the current context?

      1 Reply Last reply
      0
      • X xnaLearner

        Hey Guys...so trying to get my head around MVC My Index for holiday page is linked to the model

        @model HolidayBookingApp.Models.HolidayList

        Im trying to pull the value of Holidays remaining from the HList4DD (HolidayListForDropDown) which is coming from the HolidayList.cs page. I can get it through...

        @foreach (var item in Model.HList4DD)
        {

                @Html.DisplayFor(modelItem => item.PersonId)
            
            
                @Html.DisplayFor(modelItem => item.HolidayDate)
            
            
            @Html.DisplayFor(modelItem => item.Person.HolidaysRemaining)
        

        Although this displays the holidays remaining for every holiday booked. So if 20 holidays is the limit (4 booked and 16 remaining) this will produce a list of the dates of holidays booked i.e 4 records stating which date is booked, but it will show the '16' holidays remaining 4 times as well. Yes, this is because it is inside the for loop but I tried to display it on its own and it didnt work

        @Html.DisplayFor(model => model.HList4DD.//what do i add here?

        Also tried to add

        Person person = new Person();
        currentHolidaysRemaining = person.HolidaysRemaining;

        to the HolidayList. cs then in the view do

        @Html.DisplayFor(model => model.currentHolidaysRemaining)

        but its not pulling across the correct value, just returning 0 please advise....thanks

        D Offline
        D Offline
        David C Hobbyist
        wrote on last edited by
        #3

        Maybe you are over thinking the problem.

        xnaLearner wrote:

        @foreach (var item in Model.HList4DD) { <tr> <td> @Html.DisplayFor(modelItem => item.PersonId) </td> <td> @Html.DisplayFor(modelItem => item.HolidayDate) </td> <td> @Html.DisplayFor(modelItem => item.Person.HolidaysRemaining) </td>

        Then you just increment the value of i. Hope this helps. [edit] fixed formating.

        Frazzle the name say's it all
        Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. John F. Woods

        X 1 Reply Last reply
        0
        • D David C Hobbyist

          Maybe you are over thinking the problem.

          xnaLearner wrote:

          @foreach (var item in Model.HList4DD) { <tr> <td> @Html.DisplayFor(modelItem => item.PersonId) </td> <td> @Html.DisplayFor(modelItem => item.HolidayDate) </td> <td> @Html.DisplayFor(modelItem => item.Person.HolidaysRemaining) </td>

          Then you just increment the value of i. Hope this helps. [edit] fixed formating.

          Frazzle the name say's it all
          Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. John F. Woods

          X Offline
          X Offline
          xnaLearner
          wrote on last edited by
          #4

          Yeah that worked thanks for the help frazzle

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups