【发布时间】:2013-05-25 22:08:13
【问题描述】:
我在cshtml页面上有以下代码。
<div class="buttons">
<button type="button" id="export" class="export-inventory-button" onclick="location.href='@Url.Action("ExportInventory", "Inventory")'">EXPORT INVENTORY</button>
</div>
如何在我的视图模型中进行这项工作?
我想我差不多明白了,但需要一些帮助
<div class="buttons">
<button type="button" id="export" class="export-inventory-button" data-bind="click: exportInventory">EXPORT INVENTORY</button>
</div>
我的视图模型有这个代码:
function exportInventory() {
filtererGridData = vm.details;
var json = ko.mapping.toJSON(vm.details);
$.ajax({ url: '/Inventory/ExportInventory', type: 'POST' }).done(function (data) {
$('#export').html(data);
}).fail(function (data) {
toastr.warn('Could not export data, please contact LGL.');
});
}
我试过这个,但我得到了错误:
function exportInventory() {
filtererGridData = vm.details;
var json = ko.mapping.toJSON(vm.details);
$.ajax({ url: 'location.href="@Url.Action("ExportInventory", "Inventory")"', type: 'POST' }).done(function (data) {
window.location.href = responseText.url;
$('#export').html(data);
}).fail(function (data) {
toastr.warn('Could not export data, please contact LGL.');
});
}
谁能帮我解决这个问题?
【问题讨论】:
-
你会遇到什么错误?
-
第一个只是将数据转储到屏幕上。第二个返回 404 错误。 Url not found ="@Url.Action("ExportInventory", "Inventory")。我认为它无法正确解析行。
-
你的 javascript 在你的 cshtml 页面中吗?
-
函数exportInventory在viewmodel中
标签: asp.net-mvc razor knockout.js