【问题标题】:Using @page Route Template breaks razor component in razor page使用@page Route Template 会破坏 razor 页面中的 razor 组件
【发布时间】:2020-04-29 04:13:48
【问题描述】:

我有以下剃须刀页面Index.cshtml:

@page "/Test/{value?}"
@model Test01.Areas.Test.Pages.IndexModel


<h1>Test</h1>

<h3>@Model.value</h3>


@(await Html.RenderComponentAsync<Test01.Components.Test>(RenderMode.ServerPrerendered))

索引.cshtml.cs:

using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace Test01.Areas.Test.Pages
{
    public class IndexModel : PageModel
    {
        [BindProperty(SupportsGet = true)]
        public string value { get; set; } = "none";

        public void OnGet()
        {
        }
    }
}


带有剃须刀组件Test.razor:

<div>
    <button class="btn btn-primary" @onclick="openModal">Open Modal</button>
</div>


@if (showModal)
{
    <div class="modal" tabindex="-1" style="display:block" role="dialog">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h3 class="modal-title">Modal 1</h3>
                    <button type="button" class="close" @onclick="closeModal">
                        <span aria-hidden="true">X</span>
                    </button>
                </div>
                <div class="modal-body">
                    Modal Body
                </div>
                <div class="modal-footer">
                    Modal Footer
                </div>
            </div>
        </div>
    </div>
}


<hr />

@code {
    protected bool showModal = false;

    protected void openModal()
    {
        this.showModal = true;
    }

    protected void closeModal()
    {
        this.showModal = false;
    }
}

当我调用没有值的页面时,例如:

https://localhost:44306/Test

当我单击打开模式按钮时,它按预期工作。


当我使用如下值调用页面时:

https://localhost:44306/Test/TestValue

当我单击打开模式按钮时没有任何反应。


感谢任何帮助!

【问题讨论】:

    标签: asp.net asp.net-core razor-pages asp.net-core-3.1 razor-components


    【解决方案1】:

    不久后想通了。

    我必须补充:

    <base href="~/" />
    

    到我的_Layout.cshtml的标签

    【讨论】:

      猜你喜欢
      • 2021-04-22
      • 2021-09-29
      • 2020-05-16
      • 2019-09-18
      • 2020-07-29
      • 1970-01-01
      • 2023-02-08
      • 2020-05-23
      • 2021-12-28
      相关资源
      最近更新 更多