为什么我的剃刀页面处理程序方法实际上不是 运行?

Why isn't my razor pages handler method actually running?

bootstrap dropdown 中选择项目时,我需要更新页面模型上的 属性 以反映选择。

为了实现这一点,我正在对处理程序方法执行 ajax post 和 jquery:

function setStream(streamId, streamName) {
    // If streamId is NaN or undefined, set to 0, assuming user is viewing all streams.
    streamId = (streamId === NaN || streamId === undefined) ? 0 : streamId;
    console.log(`setStream(${streamId}, ${streamName})`);

    streamName = streamName === undefined ? "All streams" : streamName;

    $("#Booking_Stream_Id").val(streamId);
    $("#titleStream").html(`| ${streamName}`);

    // Update the stream on the model.
    const _streamId = parseInt(streamId);
    $.ajax({
        method: "GET",
        url: "/Index?handler=Stream?newStreamId=" + _streamId,
        headers: {
            "RequestValidationToken": "@token"
        },
        error: function (data) {
            console.log(data);
        }
    });
}

开发工具显示请求成功:

Request URL: https://localhost:5001/Index?handler=Stream?newStreamId=0
Request Method: GET
Status Code: 200 

但是从未命中断点并且 属性 从未更新。

public async Task OnGetStream(int newStreamId)
{
    logger.LogInformation("Current stream on booking is {stream}", this.Booking.Stream.Id);
    var stream = await context.Streams.FindAsync(newStreamId);
    if (stream is null)
    {
        // Assume user is attempting to view all streams.
        this.Booking.Stream = new Stream { Id = 0, Name = "All streams" };
    }
    else
    {
        this.Booking.Stream = stream;
    }
    logger.LogInformation("NEW stream on booking is {stream}", this.Booking.Stream.Id);
}

此外,我对记录器的调用没有写入控制台,但这是一个小问题。

鉴于上面的代码,我在这里做错了吗?我觉得这是非常简单的东西,但无论出于何种原因,我似乎无法让它工作。

如有任何帮助,我们将不胜感激。

url: "/Index?handler=Stream?newStreamId=" + _streamId,

你有一个?而不是 & 分隔您的查询字符串值。试试这个:

url: "/Index?handler=Stream&newStreamId=" + _streamId,