我假设我需要向服务器发送一个字符串,然后将过滤后的数据按字符串发送回客户端。实际上,我试图实现它,但它不起作用。服务器控制器:
private readonly DataContext _context;
private List<Clothes> vendor;
public ProductVendorController(DataContext context)
{
_context = context;
}
[HttpGet]
public async Task<ActionResult> GetClothesUrl()
{
return Ok( vendor.ToList());
}
[HttpPost]
public async Task<ActionResult> GetVendorClothes(string data)
{
var find = (from dadsa in _context.Clothes.Where(p => p.VendorCode == data)
select dadsa
).ToListAsync();
vendor = await find;
return Ok();
}
服务:
public VendorFind(Vendor: string): Observable<string> {
return this.http.post<string>(
`${environment.apiUrl}/${this.urlVendor}`,
Vendor
);
}
public VendorFindGet():Observable<Clothes>{
return this.http.get<Clothes>(
`${environment.apiUrl}/${this.urlVendor}`);
}
零件:
VendorCode:string = "";
private subscription: Subscription;
constructor(private clothesService:ClothesServiceService,private activateRoute: ActivatedRoute) {
this.subscription = this.activateRoute.params.subscribe(params => this.VendorCode = params['VendorCode'] );
}
vendorUpdated = new EventEmitter<string>();
info:any = new Clothes;
ngOnInit(): void {
this.clothesService
.VendorFind(this.VendorCode)
.subscribe((vendor: string) => this.vendorUpdated.emit(vendor));
this.clothesService
.VendorFindGet()
.subscribe((result:Clothes)=>(this.info = result));
console.log("vendor",this.VendorCode);
console.log("info",this.info);
}
路由模块:
{ path: 'Clothes/Product/:VendorCode', component: ProductPageComponent }
一个示例 HTML 组件:
<h1>{{info.name}}</h1>
<span>Артикул: {{info.vendorCode}}</span>
<h1>Цена: {{info.price}}.</h1>
UPD:正面:
{ path: 'Clothes/Product/:VendorCode', component: ProductPageComponent}
后端:
app.MapControllerRoute(
name: "ProductVendor",
pattern: "{controller = ProductVendor}/{action}/{id?}");
UPD 2:实际上,在产品选项卡上,当用户点击查看或输入带有文章的url时,会加载产品页面,该页面是从数据库中获取的。



让我们从服务器端的操作开始。
重写并获取
现在我们可以通过请求 http://localgost:1111/api/{controller}/getVendorClosest/{id} 获取对象
仍然需要为这个请求重新制作 Angular 服务(也许路由需要受 id 影响),所以你应该赚取加减。给女士们的唯一建议是将数据存储在服务中,然后在 html 中通过 async 管道获取...如果您不知道该怎么做,请写,我会补充答案
更新
让我们继续讨论客户端。
我们将创建模型,我们将在后面和前面工作
服务(需要实现业务逻辑)
好吧,那么显示的那一刻......我们的组件(页面本身)
好了,现在html