2

I work with Asp.net core Razor Page. I want JavaScript to load when the page loads, run when the page loads,no error is displayed on the console, my question is, did I pass the input parameters of the load function correctly?

public IActionResult OnGetShowComment(long id,int pageId=1 )
 {
  Comments=_CourseQuery.GetComment(User.Identity.Name,id,pageId);        
  return Partial("ShowComment",Comments);      
 }

JavaScript code:

$(function() {                     
$("#listComment").load("/Course/ShowCourse?handler=ShowComment" + 
@Model.ShowCourse.Id);     
});
     
    
2
  • So you want to pass @Model.ShowCourse.Id to OnGetShowComment,and return a partial view? Commented Dec 16, 2021 at 5:22
  • Yes exactly, I think the problem is passing the entries right ?? Commented Dec 16, 2021 at 5:25

1 Answer 1

1

If you want to pass @Model.ShowCourse.Id to OnGetShowComment in url,You need to use "/Course/ShowCourse?handler=ShowComment&&id=" + @Model.ShowCourse.Id,or it will call a handler which name is ShowComment" + @Model.ShowCourse.Id with "/Course/ShowCourse?handler=ShowComment" + @Model.ShowCourse.Id.Change your js like this:

$(function() {                     
$("#listComment").load("/Course/ShowCourse?handler=ShowComment&&id=" + 
@Model.ShowCourse.Id);     
});
Sign up to request clarification or add additional context in comments.

4 Comments

Thank you very much for your answer. It runs when I do not send any parameters in the load function, but when I try to send the parameter, unfortunately it does not run at all, it is very strange to me, what could be the reason?
Have you tried my answer,?The format of url in your question is wrong.
Yes, I did not know how to use the parameter in the load function. I found out with your answer. Thank you very much. Yes, I used your solution exactly, but the load function does not run with the parameter, it runs without the parameter.
the premise of the answer is correct, but it's typo'd &&id and also handler is not a parameter to this action that @zeze provided to begin with. That is, zeze, you aren't/weren't showing us the correct endpoint/action here. However, assuming the OnGetShowComment is defined on the default controller for the Course Area, you should just be able to call/load a GET to @($"/Course/ShowComment?id={Model.ShowCourse.Id}") since OnGetShowComment is {HttpMethod}{Action} by convention.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.