M
M
mindgrow2018-02-12 13:23:15
JavaScript
mindgrow, 2018-02-12 13:23:15

ASPMVC JS - how to call a controller action from a JS method without specifying a host and port?

Good afternoon.
There is a method in which I would like to specify the URL without the host and port, i.e. in the form "/home/ToCancel?id=", but if the host and port are not specified, then nothing works. How can I do that?
$.ajax({
type: "GET",
url: " localhost:18459/home/ToCancel?id= " + id,
data: id,
contentType: "application/json; charset=utf-8",
dataType: "json ",
success: function (data) { alert(data); },
failure: function (errMsg) {
alert(errMsg);
}
});

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
mindgrow, 2018-02-24
@mindgrow

I did it this way:
location.href = "/Home/Day?selectedDate=" + date.format("YYYY-MM-DD");
Url.Action - I can't use it, because this transition is performed in the JavaScript fullcalendar event handler.

K
Konstantin Borovik, 2018-02-12
@PushMeNow

well, in general, it's better not to specify the url explicitly, but to trust the compiler and call the Url.Action("controller method") method, which will render the correct address. about your question: try to create a virtual directory on the local iis in the project settings, and write the path you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question