如何使用 C# 从文本区域获取用户输入
我试图获取用户在页面上的文本区域中输入的值,并将该值作为字符串存储在变量中。
我花了一个多小时研究从 C# 中的文本区域获取值的所有不同方法,并尝试了示例代码的多种组合,并尝试使其适应我的情况,但它们都不起作用。要么该库不再存在,要么示例代码有问题,我不想修复 8 年前的问题。
2022 年是否有任何新方法可以获取我的 razor 页面文本区域中的值并将其存储在字符串中,以便我可以根据我的需要重新使用它?
我看过关于堆栈溢出的帖子,该帖子已发布超过 8 年,但它不起作用,或者我实施错误。
I'm trying to get the value of what the user has inputted in my textarea on my page and store that value as a string in a variable.
I have spent over an hour doing research on all different ways of getting the value from a textarea in C# and tried many combinations of example code and tried to adapt it to mine but neither of them work. Either the library doesn't exist anymore or something is wrong with example code and I don't want to fix something that is 8+ years old.
Is there any new ways in 2022 to get the value in my razor page textarea and store it in a string so I can re-use it for my needs?
I have seen the post on stack overflow that has been posted over 8+ years and it doesn't work or I'm implementing it wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将其放入 JavaScript 函数中,然后在 onlcick(如提交按钮)和/或文本区域上调用 OnTextChanged。
you can put that in a javascript function then gets called on onlcick (like a submit button) and or on the textarea as OnTextChanged.
您必须提供文本区域的 Id 或使用 Html 帮助器方法来获取它。这是一个工作示例:
You have to provide the textarea's Id or use the Html helper method to get it. Here is a working example: