C#C
C#4y ago
20 replies
kunio_kun

❔ ASP.NET Core MVC Put Value to Route on Form Submit

Hi,

I have this action on Home controller
public async Task<IActionResult> Index(EventsFilterOptionsViewModel? filters, bool enableFilter)


I want index to accept filter options on filters, but I realized that although that I don't enter any values in input fields, the model filters won't ever be null. So I can't check for filters to be null since it is not even null when the route is
/
.

I was thinking maybe i can add that enableFilter into that action, and then have asp-route-enableFilter on my form,

<form asp-controller="Home" asp-action="Index" method="get" asp-route-enableFilter="true">

but i also realized even if i submit the form, it does not put enableFilter query string on the route.

Is there a way to achieve this?

Thanks in advance
Was this page helpful?