我是MVC的新手。我已经在调试模式下测试了我的站点。到目前为止,没有问题。但是,当我将其部署到本地主机时,出现问题“ POST http://localhost/Home/GetEnumerationList 404(未找到)”。似乎无法在控制器中调用动作。当我查看地址时,它显示为“ http://localhost/mymvcsite”而不是“ http://localhost”。我还使用Postman进行了测试,当我仅以“ http://localhost/mymvcsite/Home/GetEnumerationList”的身份运行post时,我会得到结果。
有没有一种方法可以设置我的iis从“ http://localhost/mymvcsite”中删除“ mymvcsite”?
这是在Controller中调用Action的JQuery。
<script>
var popup, dataTable;
$(document).ready(function () {
dataTable = $("#batchTable").DataTable({
"ajax": {
"url": "/Home/GetEnumerationList",
"type": "POST",
"datatype": "json"
},
"columns": [
{ "data": "EnumType", "name":"EnumType" },
{ "data": "EnumValue", "name": "EnumValue" },
{ "data": "EnumText", "name": "EnumText" },
{ "data": "IsDeleted", "name": "IsDeleted" },
{
"data": "EnumId", "render": function (data) {
return "<a class='btn btn-default btn-sm' onclick=PopupForm('@Url.Action("AddOrEdit","Home")/" + data +"')><i class='fa fa-pencil'></i> Edit</a><a class='btn btn-danger btn-sm' style='margin-left: 5px' onclick=Delete(" + data +")><i class='fa fa-trash'></i> Delete</a>";
},
"orderable": false,
"searchable": false,
"width": "150px"
},
],
"processing": "true",
"serverSide": "true",
"order": [0, "asc"]
});
});
function PopupForm(url) {
var formDiv = $('<div/>');
$.get(url)
.done(function (response) {
formDiv.html(response);
popup = formDiv.dialog({
autoOpen: true,
resizable: false,
title: "Add Enum",
height: 470,
width: 300,
close: function () {
popup.dialog('destroy').remove();
}
});
});
}
function SubmitForm(form) {
$.validator.unobtrusive.parse(form);
if ($(form).valid()) {
$.ajax({
type: "POST",
url: form.action,
data: $(form).serialize(),
success: function (data) {
if (data.success) {
popup.dialog('close');
dataTable.ajax.reload();
$.notify(data.message, {
globalPosition: "top center",
className: "success"
})
}
}
});
}
return false;
}
function Delete(id) {
if (confirm("Are you sure you want to delete this data?")) {
$.ajax({
type: "POST",
url: '@Url.Action("DeleteEnum", "Home")/' + id,
success: function (data) {
if (data.success) {
dataTable.ajax.reload();
$.notify(data.message, {
globalPosition: "top center",
className: "success"
})
}
}
}
)
}
}
</script>
希望有人可以指导我。
答案 0 :(得分:0)
您可能需要在后端设置映射到mymvcsite
的默认路由。
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "mymvcsite", action = "Index", id = UrlParameter.Optional }
);
答案 1 :(得分:0)
我没有将站点添加为“默认网站”的虚拟目录,而是添加了新网站并将其指向我的webroot物理路径。我希望这对以后的任何人都有帮助。