Я пытаюсь заполнить Vue данными из JsonResult
запроса AJAX. Мой Vue получает данные просто отлично, когда я кодирую его из моей модели просмотра, но не тогда, когда я пытаюсь получить его с помощью AJAX. Вот как выглядит мой код:
<script type="text/javascript">
var allItems;// = @Html.Raw(Json.Encode(Model));
$.ajax({
url: '@Url.Action("GetItems", "Settings")',
method: 'GET',
success: function (data) {
allItems = data;
//alert(JSON.stringify(data));
},
error: function (error) {
alert(JSON.stringify(error));
}
});
var ItemsVue = new Vue({
el: '#Itemlist',
data: {
Items: allItems
},
methods: {
},
ready: function () {
}
});
</script>
<div id="Itemlist">
<table class="table">
<tr>
<th>Item</th>
<th>Year</th>
<th></th>
</tr>
<tr v-repeat="Item: Items">
<td>{{Item.DisplayName}}</td>
<td>{{Item.Year}}</td>
<td></td>
</tr>
</table>
</div>
Это со всеми надлежащими включениями. Я знаю, что @Url.Action("GetItems", "Settings")
возвращает правильный URL-адрес, и данные возвращаются, как ожидалось (как проверено предупреждением в функции успеха (см. Комментарий в функции успеха в AJAX). Заполнение его так: var allItems = @Html.Raw(Json.Encode(Model));
работает, но AJAX запрос не делает. Я что-то делаю неправильно?