gsiradze
gsiradze

Reputation: 4733

Retrieve partial view data

I have menu and using this I'm rendering partial view in my index page

@Ajax.ActionLink("week I", "firstWeekWinners", new
{

}, new AjaxOptions()
{
    HttpMethod = "GET",
    UpdateTargetId = "weeWinnersDIv",
    InsertionMode = InsertionMode.Replace
}, new { @class = "weekDays wactive" })

and there's partial view controller:

 public PartialViewResult firstWeekWinners()
    {
        ViewBag.laptopWinners = db.firstWeekLaptopWinner().ToList();
        ViewBag.tabWinners = db.firstWeekGalaxyWinner().ToList();
        ViewBag.ipodWinners = db.firstWeekIpodWinner().ToList();
        ViewBag.headPhonesWinners = db.firstWeekHeadPhonesWinner().ToList();
        ViewBag.kingstonWinners = db.firstWeekkingstonUsbWinner().ToList();

        return PartialView();
    }

and partial view:

  @if (ViewBag.laptopWinners != null)
{
    <div class="winnersPrizeOverflow">
        <div class="winnersPrizePic"></div>
        <div class="winnersAllprizeLeft"><p>12</p></div>
    </div>
    foreach (var q in ViewBag.laptopWinners)
    {
        <span>@q.firstName</span>
        <br />
        <span>@q.lastName</span>
        <br />
        <span>@q.fbId</span>
        <br />
        <span>@q.sumOfBids</span>
        <br />
    }
}

If I'll click to this ajax.actionlink it renders this view but without this if I'll put @Html.Partial("firstWeekWinners") it doesn't goes in controller to retrieve my data. How can I improve that?

Upvotes: 1

Views: 785

Answers (1)

user3559349
user3559349

Reputation:

To call your firstWeekWinners method use @Html.Action(), not @Html.Partial()

@Html.Action("firstWeekWinners")

Refer to the documentation for the various overloads, and these question/answers explaining the differences and usage.

Upvotes: 2

Related Questions