0

I am using a Functions class written in VB on my Razor Page. The page does what it is asked to do but the Next Date calculation is stuck on the first row.

@page
@model Moderate.Pages.DanceList.ThisCityModel
@using VB_Stuff.VB_Stuff;

Then I am building a table and displaying the data with a For Each loop.

<tbody>
    @foreach (var item in Model.Dances_Moderated)
    {

That is all fine and dandy and each new value per row is displayed except when I get to the column that calls the VB functions to calculate the "Next Date".

Only the first row's data is sent to the Next Date functions so as the For Each iterates through the numerous rows, the data does not change, only the first row's data is sent to the functions resulting in all rows displayed having that first value for that column. Other columns change base on data changing.

   <td>

        @{
            DateStuff obj = new DateStuff();


            string strTodayTomorrow = obj.fTodayTomorrow(Model.Dances_Moderated[0].RecurYesNo, Model.Dances_Moderated[0].SingleDate, Model.Dances_Moderated[0].RecurWeekOfMonth, Model.Dances_Moderated[0].RecurDayOfWeek);


            if (strTodayTomorrow == "")
            {
                string NextEvent = obj.fNextEvent(Model.Dances_Moderated[0].RecurYesNo, Model.Dances_Moderated[0].SingleDate, Model.Dances_Moderated[0].RecurWeekOfMonth, Model.Dances_Moderated[0].RecurDayOfWeek);

                @Html.Raw(NextEvent)

            }
            else
            {
                @Html.Raw(strTodayTomorrow)

            }
        }
    </td>

Oh, and these Data math functions work flawlessly in several other VB.Net apps I have.

JustJohn
  • 1,362
  • 2
  • 22
  • 44
  • In the ``, shouldn't `Model.Dances_Moderated[0].whatever` be `item.whatever`? – Andrew Morton Jun 23 '22 at 20:27
  • Yes. That worked. please make this an answer. Not sure, but all Next Dates are off by one. I can figure that out. Thanks – JustJohn Jun 23 '22 at 22:09
  • I'm glad to hear that fixed it, but I think we should put this down as a typo as the only problem, as presented, was that the wrong variable was used. – Andrew Morton Jun 24 '22 at 05:51
  • 1
    Well. I had no idea that your solution would work. I was just trying to find something that Visual Studio would not underline in red. It was not a typo, it was me thinking because it was not underlined in red, that it was correct. Either way. Thanks. moving on – JustJohn Jun 25 '22 at 21:23

0 Answers0