我有以下剃须刀页面 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()
{
}
}
}
使用 razor 组件 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/TestValue
当我单击打开模式按钮时没有任何反应。
任何帮助表示赞赏!