只是想在asp.net mvc上學習ajax,但不知道它有什麼問題嗎?ASP .NET MVC Ajax請求內部服務器錯誤?
我的控制器類方法=>
[HttpPost]
public JsonResult Getdata(string batchcode)
{
///var studentid = db.Studentassignbatches.Where(x => x.batch_code == batchcode).Select(x => new Studentassignbatche { UserId = x.UserId }).ToList();
return Json("hi",JsonRequestBehavior.DenyGet);
}
和我的視圖和AJAX請求>
<select onchange="ShowBatchCode()" id="BatchList" class="form-control input-lg">
<option class="pull-left" value="CCNA Security-1">CCNA Security-1</option>
<option class="pull-left" value="CCNA Security-2">CCNA Security-2</option>
<option class="pull-left" value="JNCSP-SEC-1">JNCSP-SEC-1</option>
<option class="pull-left" value="Oracle Database 12c-1">Oracle Database 12c-1</option>
</select>
和AJAX =>
<script type="text/javascript">
function ShowBatchCode() {
var batchcode = $('#BatchList').val();
$.ajax({
type: 'POST',
dataType: 'json',
contentType: 'application/json',
url: 'Getdata',
data: { batchcode: batchcode },
success: function (data) {
alert(data);
},
error: function (result) {
alert('Something Went Wrong!');
}
});
}
,它總是顯示我警告「有些事情發生了翁!」。所以我調試我的網頁,我發現=>
505內部服務器Error.i不知道如何解決it.and嘗試刪除 [Httppost],並嘗試使用
data: batchcode,
但沒有什麼適用於我。請幫我嗎?任何人!!!!!
contentType:'application/json',,您需要將數據更改爲json –
data:JSON.stringify({batchcode:batchcode}) –
嘗試給控制器名稱,如果名稱是YourController,那麼url應該是'Your/Getdata' – User3250