[英]Setting EditorFor value in razor
I have dropdownlist 我有下拉列表
<div class="form-group">
@Html.LabelFor(model => model.grpid, "grpid", new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("grpid", String.Empty)
@Html.ValidationMessageFor(model => model.grpid)
</div>
</div>
and editorfor textbox in a razor view. 以及在剃刀视图中的文本框编辑器。
<div class="form-group">
@Html.LabelFor(model => model.code, new { @class = "control-label col-md-2"})
<div class="col-md-10">
@Html.EditorFor(model => model.code, new { @id = "codeid" })
@Html.ValidationMessageFor(model => model.code)
</div>
</div>
When user select something from dropdown, i need to put selected data into textbox. 当用户从下拉列表中选择内容时,我需要将所选数据放入文本框。 I tried with jquery 我尝试了jQuery
<script type="text/javascript">
$(function () {
$('select#grpid').change(function () {
var gr = $('#grpid').val()
$('codeid input').val(gr)
})
});
</script>
but nothing happened. 但是什么也没发生。 When i "alert(gr)" popup shows with right value, but i can't get it into textbox. 当我“警报(gr)”弹出窗口显示正确的值时,但我无法将其插入文本框。
can someone help me with this? 有人可以帮我弄这个吗?
Have you checked the selector for the text input is correct? 您是否已检查选择器以确保文本输入正确? It looks like it should be #codeid
because you've said said @id="codeid"
& you probably don't need the input
part, but that depends on what html your editorfor
generates 看起来应该是#codeid
因为您说过@id="codeid"
,并且您可能不需要input
部分,但这取决于您的editorfor
生成的html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.