简体   繁体   English

将值从“选择asp-for”传递到“ textarea” asp.net核心剃须刀

[英]Passing value from “select asp-for” to a “textarea” asp.net core razor

I would like to know how to pass the value of the asp-for select description to a textarea on the same page after user picks the item. 我想知道如何在用户选择项目后将asp-for选择描述的值传递给同一页面上的textarea。

Cshtml: CSHTML:

 <select asp-for="ContasReceberVM.ContasReceber.PessoaId" asp-items="Model.ContasReceberVM.PessoaVM.ToSelectListItemNome(Model.ContasReceberVM.ContasReceber.PessoaId)" class="form-control"></select>

 <textarea asp-for="ContasReceberVM.ContasReceber.Observacao" class="form-control"></textarea>

You're confusing code that runs server-side with user interactions that happen client-side. 您将在服务器端运行的代码与在客户端发生的用户交互混淆了。 Once the user can do something like select an item from a drop down list, the server is done . 一旦用户可以执行诸如从下拉列表中选择项目之类的操作, 服务器就完成了 At that point, all you've got is a DOM created from the HTML that was sent as the server's response. 到那时,您所要做的就是从HTML创建的DOM,该DOM作为服务器的响应发送。 You'd need to use JavaScript to access the select element in the DOM and get its currently selected value. 您需要使用JavaScript来访问DOM中的select元素并获取其当前选定的值。 Then, you'd also use JavaScript to select the textarea element from the DOM and alter its content. 然后,您还将使用JavaScript从DOM中选择textarea元素并更改其内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM