Reputation: 412
I have a problem with actions that have POST attribute. when I used of IIS Express Server everything is OK , but when I use of Local IIS just GET actions worked fine, and when call post actions in my web application give me following error:
HTTP Error 404.0 - Not Found The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
for example this action in CallController:
[HttpPost]
public PartialViewResult Connecting(FarakhanModels fara)
{
try
{
fara.IP = fara.IP.Trim();
IPAddress IP = IPAddress.Parse(fara.IP);
socket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
socket.Connect(IP, fara.Port);
fara.IsConnected = true;
}
catch (Exception ex)
{
fara.ErrorMessage = ex.Message;
fara.IsConnected = false;
}
return (PartialView(viewName: "_Partial_Connect", model: fara));
}
with this view:
<h4>Call group</h4>
<hr />
<div id="connect">
<div id="loading">
<img src="~/Images/ajax-loader.gif" title="loading" />
Loading... Please Wati !
</div>
<br />
<div class="col-md-9 col-sm-9">
<span class="col-md-3">Connect to server:</span>
<input type="search" id="ip" />
</div>
<br />
<br />
<div class="col-md-9 col-sm-10">
<span class="col-md-3 col-sm-3">Port:</span>
<input type="search" id="port" />
</div>
<br />
<br />
<br />
<div class="col-md-2 col-md-offset-3">
<button type="button" class="btn-primary" id="btnConnect">Connect</button>
@*<input type="button" id="btnConnect" name="btnConnect" value="Connect" style="width:120px" />*@
</div>
<div class="col-md-12" id="message">
</div>
<br />
<br />
@section Scripts {
<script>
$(document).ready(function () {
$("div#loading").hide();
$("div#call").hide();
$("button#btnConnect").click(function () {
$("div#message").html("");
$("div#loading").show();
$("button#btnConnect").hide();
var varIp = $("input#ip").val();
var varPort = $("input#port").val();
var varData =
{
ip: varIp,
port: varPort,
};
$.ajax({
type: "POST",
dataType: "html",
data: varData,
url: "/Call/Connecting",
error: function (response) {
$("div#message").html(response.error.toString());
},
success: function (response) {
$("input#ip").val("");
$("input#port").val("");
$("div#call").show();
$("div#connect").hide();
$("div#partialView").html(response);
},
complete: function (response) {
$("div#loading").hide();
$("button#btnConnect").show();
}
})
})
})
</script>
}
when I click on Connect button, Ajax not found the Url:/Call/Connecting
Upvotes: 2
Views: 1325
Reputation: 2105
My suspicion would be the url used in the ajax call:
url: "/Call/Connecting"
It is going from the root path. You'd get 404 if you deployed the app in an environment where "/Call" is not the root. For instance, if you deployed your app at http://example.com/my_cool_app. Then the url should be "/my_cool_app/Call/Connecting" instead. I'd recommend using Url.Action helper to build your action endpoint dynamically instead of hard coding it.
Upvotes: 3