我正在尝试的是将参数从打字稿传递给控制器。但它没有传递给方法。
下面是我的打字稿代码,
multiCountryConfig() {
var multiCountry = "Test";
this.http.get('/Home/MultiCountryConfiguration', {
params: {
multiCountry: multiCountry,
}
}).subscribe(result => {
console.log(result)
}, error => {
console.log(error)
});
}
下面一个是我的家庭控制器方法代码,
[HttpGet]
public IActionResult MultiCountryConfiguration(string multiCountry)
{
var key = "test";
var value = "en-gb";
CookieOptions options = new();
options.Expires = DateTime.Now.AddHours(1);
HttpContext.Response.Cookies.Append(key, value, options);
return Ok("created");
}
我不知道是否正确。请有人指导我。谢谢你。
我正在尝试的是将参数从打字稿传递给控制器。但它没有传递给方法。
得到相同的 404 错误。获取 https://localhost:44335/Home/MultiCountryConfiguration?multiCountry=Test 404
要解决此问题,请尝试修改如下操作方法。
[HttpGet("/Home/MultiCountryConfiguration")]
public IActionResult MultiCountryConfiguration([FromQuery]string multiCountry)
{
//...
此外,请确保您的后端站点托管在 上https://localhost:44335
,而不是其他端口或 http。
注意:您的 Angular 前端代码似乎没问题,它可以帮助发出 http 请求并通过查询字符串传递数据。如果后端的路由没问题,它应该会按预期工作。
来自前端的请求
后端操作方法
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句