示例
如何像这样显示@bind值:设计值
代码如下:
产品.cs
namespace Shared.Domains
{
public class Product
{
public string Name { get; set; }
public string Design { get; set; }
}
}
产品控制器.cs(Web-Api(
[HttpGet("get")]
public async Task<ActionResult<List<Product>>> Get()
{
return await _context.Products.ToListAsync();
}
ProductsDetails.razor(代码(
private Product design;
private async Task<IEnumerable<Product>> Design(string value)
{
var data = await HttpClient.GetFromJsonAsync<List<Product>>("/products/get");
data = data.Select(x => new Product
{
Design = x.Design
}).ToList();
// if text is null or empty, show complete list
if (string.IsNullOrEmpty(value))
return data;
return data.Where(x => x.Design.Contains(value, StringComparison.InvariantCultureIgnoreCase));
}
ProductsDetails.razor(剃须刀(
<MudAutocomplete T="Product" Label="Design" ResetValueOnEmptyText="true"
@bind-Value="@design" SearchFunc="@Design" MaxItems="null"
ToStringFunc="@(e=> e == null ? null : e.Design)" />
@(design?.ToString() ?? "Not selected")
我的输出是共享的。域。产品
问题已解决。
应该这样打字!
@(design != null ? design.Design : "Not selected")