1

I am working on a webpage where I have to filter results using value from the select menu's selected option when the user clicks on filter button by sending a get parameter to the index method.

2 Answers 2

1

refId is never passed into the Index method

In your code, we can find that you specify asp-for="@Model.FirstOrDefault().RefereeId" for your <select> tag, if you check the source code of this dropdown in browser, you would find name attribute value is RefereeId (not refId) as below. So it would pass something like RefereeId=168 through querystring to your action, and parameter refId of your action would always be 0, which cause the issue.

enter image description here

To fix it, you can try to rename your action parameter to RefereeId, like below.

public async Task<IActionResult> Index(int RefereeId)
{
    //code logic here

Or modify view page code to set name of <select> tag with "refId".

<select name="refId" asp-items="@ViewBag.PersonId"></select>
Sign up to request clarification or add additional context in comments.

Comments

0

If you don't have a custom route defined, the default routing in asp.net core uses id.

Replace the refId parameter to id.

public async Task<IActionResult> Index(int id)
{
    // ...

    if (id != 0) //always remains 0
    {
        games = games.Where(g => g.RefereeId == id);
    }

    // ...
}

Comments

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.