Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Controllers do not pass arguments to ViewViewComponentResults. #4004

Closed
LDP-Dries opened this issue Jan 27, 2016 · 2 comments
Closed

Controllers do not pass arguments to ViewViewComponentResults. #4004

LDP-Dries opened this issue Jan 27, 2016 · 2 comments
Assignees
Milestone

Comments

@LDP-Dries
Copy link

Hi,

I've run into a small problem which I wish to confirm.

With the recent changes to ViewComponents it is now called as such:

@await Component.InvokeAsync("Page", new { Model.MenuPageId })

Inside a Razorview the argument is passed correctly.
However the argument is not passed when calling it from a Controller as such:

    public class PageController : Controller
    {
        public IActionResult PagePreview(long id)
        {
            if (id == 0)
                return RedirectToAction("Index");
            var p = new Dictionary<string, object>();
            p.Add("menuPageId", id);
            return ViewComponent("Page",p);
        }
    }

I've also tried:

            return ViewComponent("Page",new { id } );
            return ViewComponent("Page",new { id } );
            return ViewComponent("Page",new {menuPageId = id});

ViewComponent code:

    public async Task<IViewComponentResult> InvokeAsync(long menuPageId)
        {
            IEnumerable<VMMenuPageEdit.VMArticle> q = from articlePI in _context.ArticlePageItems
                    join articleI in _context.Articles on articlePI.ArticleId equals articleI.Id
                    where articlePI.MenuPageId.Equals(menuPageId)
                    && articlePI.GetType().Equals(typeof(ArticlePageItem))
                    select new VMMenuPageEdit.VMArticle()
                    {
                        Id = articlePI.Id,
                        X = articlePI.XCoordinate,
                        Y = articlePI.YCoordinate,
                        Width = articlePI.Width,
                        Height = articlePI.Height,
                        ArticleId = articleI.Id,
                        Description = articleI.Description,
                        SellingPrice = articleI.SellingPrice
                    };

            return View(q);
        }

The menuPageId value in the ViewComponent remains 0 when passing through the Controller. It is the correct value when passing through a razor view.

Dependencies:

    "EntityFramework.Commands": "7.0.0-*",
    "EntityFramework.MicrosoftSqlServer": "7.0.0-*",
    "Microsoft.AspNet.Diagnostics": "1.0.0-*",
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-*",
    "Microsoft.AspNet.Mvc": "6.0.0-*",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-*",
    "Microsoft.AspNet.Mvc.ViewFeatures": "6.0.0-*",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-*",
    "Microsoft.AspNet.StaticFiles": "1.0.0-*",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-*",

DNX Version: 1.0.0-rc2-16357

Sincerely,
Dries

@Eilon
Copy link
Member

Eilon commented Feb 1, 2016

@NTaylorMullen can you take a look at this?

@NTaylorMullen NTaylorMullen added this to the 1.0.0-rc2 milestone Feb 1, 2016
NTaylorMullen added a commit that referenced this issue Feb 1, 2016
- This bit was missed when changing the `ViewComponent` invocation pattern resulting in the inability to invoke `ViewComponent`s with arguments in a `Controller`.

#4004
NTaylorMullen added a commit that referenced this issue Feb 2, 2016
- This bit was missed when changing the `ViewComponent` invocation pattern resulting in the inability to invoke `ViewComponent`s with arguments in a `Controller`.

#4004
NTaylorMullen added a commit that referenced this issue Feb 2, 2016
- This bit was missed when changing the `ViewComponent` invocation pattern resulting in the inability to invoke `ViewComponent`s with arguments in a `Controller`.

#4004
@NTaylorMullen
Copy link
Contributor

096007b

@NTaylorMullen NTaylorMullen changed the title Controller not passing arguments to ViewComponents Controllers do not pass arguments to ViewViewComponentResults. May 16, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants