iT邦幫忙

0

Blazor modal中的表單送出後,會重新刷新頁面,並且有幾個欄位的欄位名稱和值會跑到網址列

  • 分享至 

  • xImage

下面是送出資料的語法

public async Task AddRecord()
{
    var JsValue = await JS.InvokeAsync<GetJsValue>("DateTimePicker");
    workovertimeDto.WoStartTime = JsValue.woStartTime;
    workovertimeDto.WoEndTime = JsValue.woEndTime;
    workovertimeDto.WoSum = JsValue.woSum;
    workovertimeDto.WoDate = DateTime.Parse(woDate);
    workovertimeDto.CreateTime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
    try
    {
        var response = await Http.PostAsJsonAsync<WorkovertimeRecordDto>("/api/workovertime", workovertimeDto);
        var responseContent = await response.Content.ReadAsStringAsync();
        var jsonSerializerOptions = new System.Text.Json.JsonSerializerOptions
            {
                PropertyNameCaseInsensitive = true
            };
        var workovertimeData = System.Text.Json.JsonSerializer.Deserialize<WorkovertimeRecordDto>(responseContent, jsonSerializerOptions);
    }
    catch (Exception e)
    {

    }
    await JS.InvokeVoidAsync("CloseModal");
    workovertime = await Http.GetFromJsonAsync<List<WorkovertimeRecordDto>>("/api/workovertime");
}

我下中斷點後還是不知道原因出在哪
只知道這段與法還沒執行完就會刷新頁面
然後欄位名稱和值就直接跑到網址列了
像是下面這張圖這樣
https://ithelp.ithome.com.tw/upload/images/20220325/20134563RQfbTLKrnN.png

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答