我正在 ASP.NET Core Razor 頁面上實作一個表單。問題是OnPost()方法是按回車鍵(即只有當我們第一次單擊GName輸入欄位并且游標開始閃爍然后我們按下時Enter)而不是點擊按鈕點擊。
這是.cshtml檔案<Form>代碼:
<div class="card-body">
<form method="post">
<div class="form-group">
<label class="control-label lead text-center" asp-for="GName">
Enter A Name To Create Greetings
</label>
<div class="input-group">
<div class="input-group-prepend">
<div class="input-group-text">
<i class="fa fa-file-signature fa-1x"></i>
</div>
</div>
<input required type="text" style="text-transform:uppercase" asp-for="GName" class="form-control" />
</div>
</div>
<button type="button" class="btn btn-primary btn-block">Create Greetings</button>
</form>
</div>
這是OnPost()來自的方法PageModel:
[BindProperty]
public string GName { get; set; }
public IActionResult OnPost()
{
return GName != null ? RedirectToPage("./SelectGreetings", new { gname = GName }) : (IActionResult)Page();
}
uj5u.com熱心網友回復:
將按鈕型別更改submit為執行表單提交:
<button type="submit" class="btn btn-primary btn-block">Create Greetings</button>
ASP.NET Core 中的 Razor 頁面簡介
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/387432.html
