【发布时间】:2019-06-25 04:03:25
【问题描述】:
从前端(HTML/.ts 到 C# 控制器)传递一个字符串变量。
我正在浏览由非官方人员制作的 angular.io 文档和演练。我观看了视频,它似乎与我的代码无关。我在 Visual Studio 2019 中启动了一个新项目(带有 Angular 的 ASP.NET Core Web 应用程序)。有 .ts 组件和 .cs 控制器。我的 HTML 设置为接受字符串输入。我尝试过使用 HTTP POST 请求和 ajax 请求。我可能用错误的论据做错了。我咨询过
How to send data to an ASP.NET Controller with Angular2
ASP.Net MVC How to pass data from view to controller
Passing Model data from View to Controller and using its values
AngularJS & asp.net MVC - passing data to controller?
还有无数其他不在 StackOverflow 上的人。
.html
<input #box (keyup)="onKey(box.value)">
Your name is: {{name}}
.ts
onKey(value: string)
{
this.name = value;
}
我希望名称字符串在控制器中可用,我可以将其打印出来,然后在数据库中使用。
【问题讨论】:
-
你能提供更多关于你拥有什么的细节吗?提供Minimal, Reproducible Example?例如,您如何将其发送到 asp.net core(您的服务)和您的 asp.net api 控制器。
标签: c# angular typescript asp.net-core