Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过单选按钮更改视图中的结果_C#_Entity Framework - Fatal编程技术网

C# 通过单选按钮更改视图中的结果

C# 通过单选按钮更改视图中的结果,c#,entity-framework,C#,Entity Framework,您好,我编写这个示例是为了学习实体框架。 现在,我在index.cshtml上添加了两个单选按钮: <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"> <labe

您好,我编写这个示例是为了学习实体框架。

现在,我在index.cshtml上添加了两个单选按钮:

<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>

全部展示
脱销
如果我选中全部,我将显示所有条目。 如果我检查缺货我将只显示数量==0的产品

我知道我可以做这样的事情:

// 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();
        }
//获取:api/产品
[HttpGet]
公共异步任务GetProducts()
{
var products=_context.products.AsQueryable();
products=\u context.products.Where(i=>i.availablequality==0);
返回等待产品。ToListSync();
}
如何通过选中单选按钮调用此函数


谢谢大家!

您需要将单选按钮放入表单中。然后,您可以在更改单选按钮时发布此表单,如下所示:

$('input[type=radio]').on('change', function() {
$(this).closest("form").submit();});

你需要把单选按钮放在表格里。然后,您可以在更改单选按钮时发布此表单,如下所示:

$('input[type=radio]').on('change', function() {
$(this).closest("form").submit();});

好的,谢谢!现在我可以调用这个函数了。但是如何编辑显示的数据?我总是被重定向,但是我会在索引视图中显示数据。你可以使用ajax帖子来实现这一点。就像这个例子,好的,谢谢!现在我可以调用这个函数了。但是如何编辑显示的数据?我总是被重定向,但是我会在索引视图中显示数据。你可以使用ajax帖子来实现这一点。就像这个例子一样