无法让我的 Razor 页面表单达到我的 Post 断点

Can't get my Razor Page Form to hit my Post break point

我看过 但没有帮助。

Waiver.cshtml

@page
@model GCRR.Models.WaiverLookup
@{
    ViewData["Title"] = "Waiver lookup page";
}

<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">
                Sign a new or lookup an existing liability waiver
            </h1>
        </div>
    </div>
    <form method="post">
        <div class="row">
            <br />
            <h3>
                If you have signed a waiver that included the participates that are with you today, adults and/or kids, then enter your phone number or email address to lookup your waiver. You will need this when purchasing tickets.
                If you have never signed a waiver before please click the new waiver button.
            </h3>
        </div>
        <br />
        <div class="row">
            <div class="col-md-6">
                <div class="row form-group">
                    <label asp-for="Phone" class="col-xs-12">Phone</label>
                    <div class="col-xs-9"><input asp-for="Phone" class="form-control" /></div>
                    <span asp-validation-for="Phone" class="text-danger"></span>
                </div>
                <br />or<br /><br />
                <div class="row form-group">
                    <label asp-for="Email">Email</label>
                    <div><input asp-for="Email" class="form-control" /></div>
                    <span asp-validation-for="Email" class="text-danger"></span>
                </div>
                <div class="row form-group">
                    <input type="submit" class="btn btn-primary pull-right">
                </div>
            </div>
        </div>
    </form>
</div>

@section Scripts {
    @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}

Waiver.cshtml.cs

using GCRR.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using GCRR.Models;

namespace GCRR.Pages
{
    public class WaiverModel : PageModel
    {
        private IWaiverFileService _waiverFileService;

        public WaiverModel(IWaiverFileService waiverFileService)
        {
            _waiverFileService = waiverFileService;
        }

        public void OnGet()
        {

        }

        public void OnPost(WaiverLookup waiverLookup)
        {
            var waivers = _waiverFileService.SearchWaiversAsync("8137812796");
        }

        //public async Task<IActionResult> OnPostAsync(WaiverLookup waiverLookup)
        //{
        //    if (!ModelState.IsValid)
        //    {
        //        return Page();
        //    }

        //    // Do Something
        //    var waivers = await _waiverFileService.SearchWaiversAsync("8137812796");

        //    return RedirectToPage("./Index");
        //}
    }
}

这是在 Visual Studio 2022 年,我在“OnPost”方法上设置了一个断点,但是当我单击该按钮时,页面会刷新并且没有命中断点。

一定是我在这里遗漏了一些愚蠢的东西。即使我在 OnGet 方法中放置了一个在页面加载时也未命中的断点。

将您的 WaiverLookup class 留在您的模型文件夹中。

在 WaiverModel class 中,添加类型为 WaiverLookup

的 属性
public class WaiverModel : PageModel
{
   public WaiverLookup WaiverLookup { get; set;} // Your new property !!!
 
   private IWaiverFileService _waiverFileService;

   public WaiverModel(IWaiverFileService waiverFileService)
   {
       _waiverFileService = waiverFileService;
   }

   public void OnGet()
   {
   }

   public void OnPost(WaiverLookup waiverLookup)
   {
      string phoneNumber = waiverLookup.Phone; // new value submitted

      var waivers = _waiverFileService.SearchWaiversAsync("8137812796");
   }
}

在您的 Waiver.cshtml 页面中,您现在可以引用新的 属性 WaiverLookup 并访问其成员:

<input asp-for="WaiverLookup.Phone" class="form-control" />