1

Hello again i coded this example to learn entity-framework. Build a CRUD Application with ASP.NET Core 3.0 & Entity Framework 3.0 Using Visual Studio 2019

now on the index.cshtml i added two radiobuttons:

<input type="radio" name="rdbAll" value="All" id="all-1" checked>
<label for="all-1">Show all</label>
<input type="radio" name="rdbOutOfStock" value="out" id="out-1">
<label for="out-1">Show out of stock</label>

if i check All i will show all entries. if i check out of stock i will only show the products where quantity == 0

i know i can do something like that:

// GET: api/Products
        [HttpGet]
        public async Task<ActionResult<IEnumerable>> GetProducts()
        {
          var products = _context.Products.AsQueryable();
          products = _context.Products.Where(i => i.AvailableQuantity == 0);
          return await products.ToListAsync();
        }

how can i call this function by checking the radio button.

Thank you!

Silazz1378
  • 63
  • 7

1 Answers1

0

You need to put the radiobuttons in a form. Then you can post this form on changing the radiobutton like so:

$('input[type=radio]').on('change', function() {
$(this).closest("form").submit();});
  • okay thank you! Now i can call the function. But how can i edit the shown data? i get always redirected but i will the data shown in the Index View – Silazz1378 Jun 04 '20 at 14:21
  • You can use an ajax post for that. Like in this example https://stackoverflow.com/questions/5004233/jquery-ajax-post-example-with-php/5004276#5004276 – Marc Pruntel Jun 04 '20 at 14:39