It is not clear from your codes, since the ajax url is razor page route but not mvc. Do you enable both of them?
Besides, from your previous post I see that the View name is Test.cshtml
, while the Test
action return Json, so when you access /Custom/Test
, you just get the Json results instead of a View.
If the Test action is used to display the html view, I think it should return View:
public IActionResult Test()
{
return View();
}
Update:
Have an action(Test) to return View(Test.cshtml). Just reutn View()
without any data since I didn't see any place you use the model(VmIstanbul) value in your view.
public IActionResult Test()
{
return View();
}
Have another action to return data to ajax, Give it a name except Test
. For example:
public IActionResult TestSelect()
{
var data = from als in ctx.TbIstanbulCards select new { als.IstanbulCardId, als.Balance };
return Json(data.ToList());
}
And change the ajax url to TestSelect
@section Scripts{
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
type: "GET",
url: "/Customer/TestSelect",
success: function (data) {
console.log(data);
var s = '<option value="-1">Please Select a Card id</option>';
for (var i = 0; i < data.length; i++) {
s += '<option value="' + data[i].balance + '">' + data[i].istanbulCardId + '</option>';
}
$("#departmentsDropdown").html(s);
}
})
})
function getValue() {
var myVal = $("#departmentsDropdown").val();
$("#show").val(myVal);
}
</script>
}
Result:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…