Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blazor component not work in ASP.NET Core MVC when I return it a few times #18588

Closed
denmaklucky opened this issue Jan 26, 2020 · 1 comment
Closed
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved

Comments

@denmaklucky
Copy link

I have a project ASP.NET Core MVC. This project contains two controllers: Home and Movie. In HomeController I have action which return View like:

@model IEnumerable<Movie>

@{
    ViewData["Title"] = "Online Cinema";
}

<div class="row p-2">
    @foreach (var movie in Model)
    {
        <component type="typeof(MovieComponent)" render-mode="ServerPrerendered" param-Model="movie" />
    }
</div>

And in MovieController I have some action which return View like this:

@model IEnumerable<Movie>

@{
    ViewData["Title"] = $"Online Cinema - {ViewBag.Title}";
}

<div class="row p-2">
    @if (Model.Count() == 0)
    {
        <span>Sorry! We haven't this type of films!</span>
    }
    else
    {
        @foreach (var movie in Model)
        {
            <component type="typeof(MovieComponent)" render-mode="ServerPrerendered" param-Model="movie" />
        }
    }
</div>

When I return View from HomeController It's ok. Blazor component work, but when I return View from MovieController Blazor component isn't work.

In browser I found this

изображение

I use .Net Core 3.1.100
GitHub repository

@blowdart blowdart added the area-blazor Includes: Blazor, Razor Components label Jan 26, 2020
@mkArtakMSFT
Copy link
Member

Thanks for contacting us.
It looks like you're missing the <base> url in the Layout file: https://docs.microsoft.com/en-us/dotnet/architecture/blazor-for-web-forms-developers/pages-routing-layouts#base-urls
That should help.

@mkArtakMSFT mkArtakMSFT added the ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. label Jan 27, 2020
@ghost ghost added the Status: Resolved label Jan 27, 2020
@dotnet dotnet locked as resolved and limited conversation to collaborators Mar 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. Status: Resolved
Projects
None yet
Development

No branches or pull requests

3 participants