Recently, we were working on a project where my client asked me for the tab in a popup window. Something like the image given below:
The project requires to show the services based on subcategories like if the user selects SpliteACRepaire service, they get the list of split ac services, and if the user selects for windowacrepairservices, the user will get the services related to window ac services.
1) Add partial view in our case it is(_services)
Right-click on a shared folder and choose razor view.
Next, you’ll be prompted to add a razor view.
Enter the desired name and select create as a partial view
Below is the code of viewmodel
ApplicationDbContext Context public ServiceRangeViewModel(ApplicationDbContext context) { Context = context; } public List? Services { get; set; } public List? Ranges { get; set; } public async Task<List> GetRanges(int id) { Ranges =await Context.TblRange.Where(i => i.SubCategoryId == id).ToListAsync(); return Ranges; } public async Task<List> GetServices(int id) { Services = await Context.TblServices.Where(i => i.RangeId == id).ToListAsync(); return Services; }
$(function () {
$('.announce').on('click', function () {
$('#servicescontainer').load(`/Services/product?id=${$(this).data('id')}`);
$('#expfrm3').modal("show");
});
})
@page "{handler?}"
public async Task OnGetProductAsync(int id)
{
List Rangess = await context.TblRange.Where(subcat => subcat.SubCategoryId == id).ToListAsync();
List Servicess = await context.TblServices.ToListAsync();
ServiceRangeViewModel model = new ServiceRangeViewModel(context)
{
Ranges = Rangess,
Services = Servicess
};
return Partial("_ServiceDetails",model);
}
https://www.mikesdotnetting.com/article/325/partials-and-ajax-in-razor-pages