英文:
Get data on change event of select Tag helper
问题
我有一个在.NET Core MVC Razor中的项目。我正在使用select标签助手来创建下拉列表。我需要从数据库中获取某个值,并根据下拉框中选择的值在文本框中显示它。如何实现这个功能?我需要在选择值后仍然保持在同一页面,并继续填写表单。请找到我的Razor代码:
<div class="form-group row">
<label asp-for="@Model.addAppointmentInQueue.Doctor" class="col-md-3 col-form-label-lg"></label>
<div class="col-md-9">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<select id="lstdoctor" asp-for="@Model.addAppointmentInQueue.Doctor"
asp-items="@Model.addAppointmentInQueue.doctorList"
new { onchange = "return ToggleViewItems();" }
class="form-control form-control-lg selectpicker">
<option>Please select Doctor</option>
</select>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group row">
<label asp-for="@Model.addAppointmentInQueue.consultationCharges" class="col-md-3 col-form-label-lg"></label>
<div class="col-md-9">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input asp-for="@Model.addAppointmentInQueue.consultationCharges" class="form-control" type="text">
</div>
</div>
</div>
</div>
注意:这是您提供的Razor代码的翻译部分。
英文:
I have a project in .Net core MVC Razor . I am using select tag helper for drop down list. I need to get some value from database & display it in text box based on selection of select value in dropdown box. How can I achieve this? I need to remain in same page after value selected and continue with same form. Please find my Razor code :
<div class="form-group row">
<label asp-for="@Model.addAppointmentInQueue.Doctor" class="col-md-3 col-form-label-lg"></label>
<div class="col-md-9">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<select id="lstdoctor" asp-for="@Model.addAppointmentInQueue.Doctor"
asp-items="@Model.addAppointmentInQueue.doctorList"
new { onchange = "return ToggleViewItems();" }
class="form-control form-control-lg selectpicker">
<option>Please select Doctor</option>
</select>
</div>
</div>
</div>
<div class="col-md-6">
<div class="form-group row">
<label asp-for="@Model.addAppointmentInQueue.consultationCharges" class="col-md-3 col-form-label-lg"></label>
<div class="col-md-9">
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input asp-for="@Model.addAppointmentInQueue.consultationCharges" class="form-control" type="text" >
</div>
</div>
</div>
</div>
答案1
得分: 0
如果您已经可以从 GetConsultationChagesForDoctor?doctor=
返回某个字符串,下面的代码将有效:
<select id="lstdoctor" asp-for="@Model.addAppointmentInQueue.Doctor"
asp-items="@Model.addAppointmentInQueue.doctorList" onchange="myFunction(this.options[this.selectedIndex].value)"
class="form-control form-control-lg selectpicker">
<option>请选择医生</option>
</select>
<input id="textbox1" asp-for="@Model.addAppointmentInQueue.consultationCharges" class="form-control" type="text">
<script>
function myFunction(chosen) {
$.ajax("/GetConsultationChagesForDoctor?doctor=" + chosen, {
type: 'GET',
success: function (data) {
$('#textbox1').val(data);
},
});
}
</script>
英文:
If you can already return some string from GetConsultationChagesForDoctor?doctor=
,the below code works<br>
Made some change on select and input
<select id="lstdoctor" asp-for="@Model.addAppointmentInQueue.Doctor"
asp-items="@Model.addAppointmentInQueue.doctorList" onchange="myFunction(this.options[this.selectedIndex].value)"
class="form-control form-control-lg selectpicker">
<option>Please select Doctor</option>
</select>
<input id="textbox1" asp-for="@Model.addAppointmentInQueue.consultationCharges" class="form-control" type="text">
<script>
function myFunction(chosen) {
$.ajax("/GetConsultationChagesForDoctor?doctor=" + chosen, {
type: 'GET',
success: function (data) {
$('#textbox1').val(data);
},
});
}
</script>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论