1

When I use jQuery post function in my js file, like this:

$.post("/map/GetWindowedMapInfo", { 
    width: windowWidth * 2, 
    height: windowHeight * 2, 
    xCoord: winXCoord, 
    yCoord: winYCoord }, function (data) {...});

It work well in vs2010 developer server, but failed when publishing the ASP.NET MVC project on IIS, the associated controller function did not run anymore, because url was wrong. I have to use '<%= Url.Content("~/map/GetWindowedMapInfo") %>' to replace old url, but this can only work in the .aspx or .ascx file. Do you know any method to make a usable url in js file, not using <%=Url.Content(...) %> function, because I don't want to put my js file in aspx page.

1

1 Answer 1

1

You shouldn't be hardcoding urls like this:

$.post("/map/GetWindowedMapInfo", { 
    ...    
});

Instead you should use URL helpers:

$.post("@Url.Action("GetWindowedMapInfo", "map")", { 
    ...    
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.