Hi @Hursh, I had a test in my side with an MVC application, here's my codes, could you please help check whether the radio buttons I used solved your issue? In my test, my radio button selected option will be passed to the Controller action. Then we can modify the query clause to query out the required data.
@model WebAppDefIdentity.Models.MovieGenreViewModel
@{
ViewData["Title"] = "Index";
}
<h1>Index</h1>
<form asp-controller="Movies" asp-action="Index" method="get">
<p>
Title: <input type="text" asp-for="SearchString" />
Gender:
<span class="col-md-10">
<span style="margin-left:10px;">
@Html.RadioButtonFor(model => model.Gender, "Male") Male
</span>
<span style="margin-left:10px;">
@Html.RadioButtonFor(model => model.Gender, "Female") Female
</span>
</span>
<input type="submit" value="Filter" />
</p>
</form>
<table class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(model => model.Movies![0].Title)
</th>
<th>
@Html.DisplayNameFor(model => model.Movies![0].ReleaseDate)
</th>
<th>
@Html.DisplayNameFor(model => model.Movies![0].Genre)
</th>
<th>
@Html.DisplayNameFor(model => model.Movies![0].Price)
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.Movies!)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.ReleaseDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.Genre)
</td>
<td>
@Html.DisplayFor(modelItem => item.Price)
</td>
</tr>
}
</tbody>
</table>
public class MovieGenreViewModel
{
public List<Movie>? Movies { get; set; }
public string? SearchString { get; set; }
public string? Gender { get; set; }
}
public async Task<IActionResult> Index(string searchString, string gender)
{
var movies = from m in _context.Movie
select m;
if (!string.IsNullOrEmpty(searchString))
{
movies = movies.Where(s => s.Title!.Contains(searchString));
}
var movieGenreVM = new MovieGenreViewModel
{
Movies = await movies.ToListAsync()
};
return View(movieGenreVM);
}
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Tiny