简体   繁体   中英

What is the best way to make a razor view with content that changes every time you choose a filter?

The thing my employer asked for is a razor search form for items that has optional filters that show per filter value how many items there are. For example, filter option "fruits" has option "oranges" and behind "oranges" you can see the amount of oranges. Every time a filter value is chosen, the entire content must change and the number of items behind every filter value must change because the number of items that have that value and the value of the applied filter will be less. Per filter, it must be possible to pick several values. The data has to be gained from an ASP.NET API which I also have to make. It may not be directly from the database because we want to use this API functionality for other applications as well.

An example of what I mean can be seen on this website .

All of this has to be made in ASP.NET and with an ASP.NET API.

Let me know if any clarification is needed. Thanks in advance.

Break out the dynamic content in a partial view. And create an action method on the server that takes filter parameters as input and then returns the partial view with the results. On page load use AJAX to pass the selected filter parameters and load the resulting content as a partial view. ON change of filter call the AJAX method again. Whatever HTML content is returned by the partial view, place it on the page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM