1

Im trying to redirect to a Controller from JavaScript using this line of code

 location.href = '/Dashboard/';

It redirects to the Dashboard but on my dashboard view this method is called when the document loads

 $.post("Dashboard/UsersGet", {}, function (dataSet) {
    //do something with the dataset
 }); 

I then get this error.

POST http://localhost:1414/Dashboard/Dashboard/UsersGet 404 (Not Found) 

I can see that dashboard is added to the url twice. How can I redirect to a Controller without this happening?

4

3 に答える 3

2

Urlヘルパーを使用します。

@Url.Action("UsersGet", "Dashboard")

完全なコード:

$.post('@Url.Action("UsersGet", "Dashboard")', {}, function (dataSet) {
    //do something with the dataset
 });    

Asp .Net MVC のルートは、従来の Asp.Net のようには機能しません。

于 2012-11-07T08:32:40.623 に答える
1

これを試して:

 $.post("/Dashboard/UsersGet", {}, function (dataSet) {
    //do something with the dataset
 }); 

/URLに追加します。

于 2012-11-07T08:34:56.800 に答える
0
 $.post("Dashboard/UsersGet", {}, function (dataSet) {
    //do something with the dataset
 }); 

する必要があります

 $.post("/Dashboard/UsersGet", {}, function (dataSet) {
    //do something with the dataset
 }); 

「/」がないと、投稿する URL は現在の URL に追加されます。

于 2012-11-07T08:38:07.133 に答える