0
我有folliwng腳本,實際上使兩個調用兩個不同的操作方法,並更新相關領域如何更新兩個領域: -根據返回的Json
<script type="text/javascript">
$(document).ready(function() {
$("#Switch_RackID").change(function() {
var idRack = $(this).val();
$.getJSON("/Switch/LoadDataCenterByRack", { id: idRack },
function (RackData) {
var select = $("#Switch_TMSRack_DataCenter_Name");
select.empty();
$("#Switch_TMSRack_DataCenter_Name").val(RackData.Text);
});
$.getJSON("/Switch/LoadZoneByRack", { id: idRack },
function (RackData2) {
var select = $("#Switch_TMSRack_Zone_Name");
select.empty();
$("#Switch_TMSRack_Zone_Name").val(RackData2.Text);
});
});
});
</script>
但我的問題是天氣,我可以使用getjson調用一次而不是兩次調用,然後更新相關字段?我的行動方法看起來如下: -
public JsonResult LoadDataCenterByRack(int id)
{
string datacentername = repository.FindRack(id).DataCenter.Name;
var DCData = new { Text = datacentername, Value = datacentername };
return Json(DCData, JsonRequestBehavior.AllowGet);
}
public JsonResult LoadZoneByRack(int id)
{
string zonername = repository.FindRack(id).Zone.Name;
var ZData = new { Text = zonername, Value = zonername };
return Json(ZData, JsonRequestBehavior.AllowGet);
}
任何人都可以建議嗎? 謝謝