pulling across value from list to display in view
-
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
-
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
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?
-
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
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 -
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. WoodsYeah that worked thanks for the help frazzle