0

When I logged in user visits their profile vial Manage -> Index.cshtml, I want to display to them all the orders made through the organisation which they belong to.

These orders are usually displayed in an organisation's Details.cshtml with

@{Html.RenderAction("Index", "Order", new { org = Model });}

Where model contains a ViewOrganisationViewModel, where all the orders are stored.

This works perfectly.

Now when I want to do the same for a logged in user, I tried:

Manage Index.html

@{Html.RenderAction("MyIndex", "Order");}

OrderController.cs

Here I added the MyIndex method, which first gets the user's OrganisationId in order to build the correct ViewOrganisationViewModel. This entire method runs without error.

public ActionResult Index(ViewOrganisationViewModel org)
{
    return PartialView(org.Orders);
}

public ActionResult MyIndex()
{
    Models.ApplicationUser user =
        System.Web.HttpContext.Current.GetOwinContext()
            .GetUserManager<ApplicationUserManager>()
            .FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());

    var organisationManager = new OrganisationManager();
    var org = organisationManager.Select(user.OrganisationId);

    return View("Index", org);
}

Now when the applications tries to return to Index(ViewOrganisationViewMode org), I get:

The model item passed into the dictionary is of type 'AuroraWeb.ViewOrganisationViewModel', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[AuroraWeb.ViewOrderViewModel]'.

Why is it doing this? The method does not expect an IEnumerable of the ViewModel, so am I missing something here?

I also tried changing the return line in MyIndex to

return Index(org);

But it then complains that there is no MyIndex.cshtml view (Which there isn't because I only need to return the Index view..)

I also tried

return RedirectToAction("Index", new { org = org });

but got

Child actions are not allowed to perform redirect actions.

Please let me know if I can provide any extra details.

Bassie
  • 9,529
  • 8
  • 68
  • 159
  • Your `Index.cshtml` view has `@model IEnumerable` but your passing it a single `ViewOrganisationViewModel` –  Oct 07 '17 at 12:13
  • @StephenMuecke Thank you. I was thinking of it in terms of returning the controller action but I guess it just returns the `Index` view in `OrderController` directly – Bassie Oct 07 '17 at 12:23
  • I'm guessing that you want `return View("Index", org.Orders);` (i.e as per the model/code in the `Index()` method) –  Oct 07 '17 at 12:25
  • @StephenMuecke yup, that did it. Should I close this question or do you wan to add an answer?? – Bassie Oct 07 '17 at 12:31
  • I already closed it :) –  Oct 07 '17 at 12:32

0 Answers0