locked
getting data LINQ MVC view RRS feed

  • Question

  • I'm awkward at getting data in MVC using LINQ.  I want to present all of the tours our capitol offers in date order in a view.  I'm awkward with where do to the work in MVC.  So I've passed the data using a model, and now I just want to put each days data in the list.  Is this a good way?  I'm not proud of this first attempt, and open to any help.  Thanks!

    Here's my first stab at it...  How can I stick some linq in here to just get the stuff for that day in the list at that spot?

    @{
        Layout = null;
        DateTime thisyear = DateTime.Now;
        int myyear = thisyear.Year;
        int mysecondyear = thisyear.Year + 1;

        for (int m = 1; m <= 12; m++)
        {
            string mymonth = System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat.GetMonthName(m);
            <h4 class='jQueryExpandableHeader'><strong>@mymonth  @myyear</strong></h4>
            <div>
                @for (int d = 1; d <= DateTime.DaysInMonth(myyear, m); d++)
                {
                    DateTime dt = new DateTime(2014, m, d);
                    <div><h5 class="contactHeader smaller">@dt.DayOfWeek, @mymonth @d</h5>
                        <div>
                            @for (int info = 1; info <= 20; info++)
                            {
                                foreach (var p in Model.publishedEvents){  <== would linq help here?  just get the model data where it's equal to this day?
                                <div>Hi fred - I just want the events for this day here - lots more work to do on presentation but I'd like to nail down the data piece now.  Thanks!</div>
                            }
                            }
                        </div>
                    </div>
                }
            </div>
        }

    }

    • Moved by Caillen Tuesday, May 6, 2014 6:27 AM
    Monday, May 5, 2014 2:17 PM

Answers

All replies