使用 mvc 5 将值传递给文本框
Pass value to a textbox using mvc 5
我需要将值传递给文本框,但用户不能直接写入该文本框。我正在使用 jason:
计算值
<script type="text/javascript">
$(document).ready(function () {
$("#txtid").change(function () {
$.ajax({
url: '/CommissionsFinals/GetTarifa',
type: 'GET',
contentType: "application/json; charset=utf-8",
dataType: 'json',
data: { clientID: $("#DDLCliente").val(), consultorID: $("#DDLConsultor").val() },
success: function (tarifa) {
//response(tarifa.
$('#txtid').val(tarifa).autocomplete
},
error: function () {
alert('Error!');
}
});
})
});
当我尝试输入不同的值时,文本框改变了他的值。该值由在 2 个不同的 DropDownLists 中选择的 2 个参数(clientId、consultorId)计算得出。从 DropDownList 中选择这 2 个值后如何自动获取值?
<th>
@Html.DropDownListFor(m =>m.ManagerId, new SelectList(ViewBag.Manager, "ManagerId", "NomeCompleto"), "Seleccione o Manager", new { @class = "form-control", @id = "DDLManager" })
</th>
<th>
@Html.Label("Consultor", htmlAttributes: new { @class = "control-label col-md-2" })
</th>
<th>
@Html.DropDownListFor(m => m.ConsultorId, new SelectList(ViewBag.Consultor, "ConsultorId", "NomeCompleto"), "Seleccione o Consultor", new { @class = "form-control", @id = "DDLConsultor" })
</th>
ajax 的成功回调是否被调用了?
$('#txtid').val(tarifa) 应该有效,但可能未达到该代码。您可以使用 breakpoint/alert 或某物进行测试。除此之外,我发现我的 ajax 电话有一个不同之处,我通常使用
输入:"POST",这对我有用。
你可以用这个
处理Javascript中的下拉变化事件
$("#test").change(function() {
alert( "do you stuff" );
});
并检查是否选择了两个下拉列表的验证,最后调用 ajax(jquery) 方法将所选值提交给控制器。
不清楚你想做什么。如果您询问如何从下拉列表中获取选定的值,您可以这样做。
$('#ConsultorId').on('change', function() {
var consultorId = $('#ConsultorId').val();
});
我需要将值传递给文本框,但用户不能直接写入该文本框。我正在使用 jason:
计算值<script type="text/javascript">
$(document).ready(function () {
$("#txtid").change(function () {
$.ajax({
url: '/CommissionsFinals/GetTarifa',
type: 'GET',
contentType: "application/json; charset=utf-8",
dataType: 'json',
data: { clientID: $("#DDLCliente").val(), consultorID: $("#DDLConsultor").val() },
success: function (tarifa) {
//response(tarifa.
$('#txtid').val(tarifa).autocomplete
},
error: function () {
alert('Error!');
}
});
})
});
当我尝试输入不同的值时,文本框改变了他的值。该值由在 2 个不同的 DropDownLists 中选择的 2 个参数(clientId、consultorId)计算得出。从 DropDownList 中选择这 2 个值后如何自动获取值?
<th>
@Html.DropDownListFor(m =>m.ManagerId, new SelectList(ViewBag.Manager, "ManagerId", "NomeCompleto"), "Seleccione o Manager", new { @class = "form-control", @id = "DDLManager" })
</th>
<th>
@Html.Label("Consultor", htmlAttributes: new { @class = "control-label col-md-2" })
</th>
<th>
@Html.DropDownListFor(m => m.ConsultorId, new SelectList(ViewBag.Consultor, "ConsultorId", "NomeCompleto"), "Seleccione o Consultor", new { @class = "form-control", @id = "DDLConsultor" })
</th>
ajax 的成功回调是否被调用了? $('#txtid').val(tarifa) 应该有效,但可能未达到该代码。您可以使用 breakpoint/alert 或某物进行测试。除此之外,我发现我的 ajax 电话有一个不同之处,我通常使用 输入:"POST",这对我有用。
你可以用这个
处理Javascript中的下拉变化事件$("#test").change(function() {
alert( "do you stuff" );
});
并检查是否选择了两个下拉列表的验证,最后调用 ajax(jquery) 方法将所选值提交给控制器。
不清楚你想做什么。如果您询问如何从下拉列表中获取选定的值,您可以这样做。
$('#ConsultorId').on('change', function() {
var consultorId = $('#ConsultorId').val();
});