我使用 Asp.net 核心 Razor Page。我希望JavaScript在頁面加載時加載,頁面加載時運行,控制臺不顯示錯誤,我的問題是,我是否正確傳遞了加載函式的輸入引數?
public IActionResult OnGetShowComment(long id,int pageId=1 )
{
Comments=_CourseQuery.GetComment(User.Identity.Name,id,pageId);
return Partial("ShowComment",Comments);
}
JavaScript 代碼:
$(function() {
$("#listComment").load("/Course/ShowCourse?handler=ShowComment"
@Model.ShowCourse.Id);
});
uj5u.com熱心網友回復:
如果你想傳遞@Model.ShowCourse.Id到OnGetShowCommenturl,你需要使用"/Course/ShowCourse?handler=ShowComment&&id=" @Model.ShowCourse.Id,否則它會呼叫一個名稱為ShowComment" @Model.ShowCourse.Idwith的處理程式。"/Course/ShowCourse?handler=ShowComment" @Model.ShowCourse.Id像這樣更改你的 js:
$(function() {
$("#listComment").load("/Course/ShowCourse?handler=ShowComment&&id="
@Model.ShowCourse.Id);
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/384705.html
