我對asp.net和MVC很新穎。mvc json請求生命週期
我正在嘗試使用json請求並填充一些文本框。
但我注意到當我使用json時,我無法訪問我視圖中其他文本框的值。 例如
string s2 = Request.Form["selectedTestCategory"];
將產生S2 =空,當我調試。 但如果我在頁面上提交按鈕,該值不爲空。 (到目前爲止,我知道我只能傳遞一個參數給控制器中的JSON方法)
我的問題是當我啓動一個json請求時會發生什麼?爲什麼我不能得到的Request.Form值[...]
感謝,
更新:
這是我的JSON
<script>
$(document).ready(function() {
$('select#testStationUniqueId').change(function() {
var testStation = $(this).val();
$.ajaxSetup({ cache: false });
$.ajax({
url: "TestInput/getTestStationInformation/" + testStation,
type: 'post',
success: function(data) {
$('#driveDetailDiv').empty();
for (var i = 0; i < data.length; i++) {
$.post('TestInput/Details/', { id: data[i] }, function(data2) {
$('#driveDetailDiv').append(data2);
});
}
}
});
});
});
這在我的控制器中
public PartialViewResult Details(string id)
{
//DriveDetails t = new DriveDetails(id);
//return PartialView("DriveDetailsPartial", t);
test_instance_input_model ti = new test_instance_input_model();
string s2 = Request.Form["selectedTestCategory"];
repository.setTestInstanceAttributes(ti, id);
return PartialView("TestInstancePartial", ti);
}
s2在Details中爲null,但是如果我使用提交按鈕,它將具有正確的值。
所以我想弄清楚爲什麼它是空的,當我發送一個JSON請求。
發佈ajax代碼和控制器齒列。還要指定您正在使用的MVC版本。 – asawyer
對不起,行動的*定義*不是它的牙科記錄。 – asawyer
謝謝,我把代碼放在我的問題 – Athena