gpt4 book ai didi

c# - 如何使用 @Html.TextBoxFor 的用户输入设置 @Html.RadioButtonFor 的值?

转载 作者:行者123 更新时间:2023-12-02 19:30:29 24 4
gpt4 key购买 nike

我有一个 Razor @Html.RadioButtonFor,它从@Html.TextBoxFor 值获取其值:

@Html.RadioButtonFor(m => m.Sms, document.getElementById('@(Model.Phone)').value, new { Id = Model.Sms })

问题在于

document.getElementById('@(Model.Phone)').value

是一段 JavaScript 代码,在这种情况下不正确,但我不知道如何重写相同的代码,使其正确。

最佳答案

Paul,我必须采用另一种方式:从文本框 onChange 中设置单选值。

看看这个:

@model string
<!DOCTYPE html>
<html>
<head>
<title>ViewA</title>
<script type="text/javascript">
function changeRadioValue(newValue) {
var radio = document.getElementById('idRadio');
if (radio != null) {
radio.value = newValue;
}
else {
//do nothing?
}
}
</script>
</head>
<body>
<div>
@Html.TextBox("theTextBox", Model, new { id = Model, onChange = "changeRadioValue(this.value)" })
@Html.RadioButton("radio", "Default radio value", new { id = "idRadio", onClick="alert(this.value)" })
</div>
</body>
</html>

radio onClick仅用于调试。

希望这有帮助

问候

关于c# - 如何使用 @Html.TextBoxFor 的用户输入设置 @Html.RadioButtonFor 的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11550532/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com