This repository was archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
Controllers do not pass arguments to ViewViewComponentResult
s. #4004
Copy link
Copy link
Closed
Description
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