1

I am using d3js library to draw charts. Here is I'm calling the action like this :

d3.json("CANCEL_REASON/Statistics2", function (data) {
....

My controller is like this :

 public class CANCEL_REASONController : Controller
    {
        private Entities3 db = new Entities3();

        public ActionResult Statistics()
        {
            return View();
        }

        public ActionResult Statistics2()
        {

        ///...
        return Json(data, JsonRequestBehavior.AllowGet);
        }

When I debug the JavaScript, I realize that it's trying to call :

http://localhost:12345/CANCEL_REASON/CANCEL_REASON/Statistics2

When I change js to this :

d3.json("/Statistics2", function (data) {
....

It's trying to call this :

http://localhost:12345/Statistics2

How should I modify my code so that it will call this :

http://localhost:12345/CANCEL_REASON/Statistics2

Thanks.

1
  • 1
    Try /CANCEL_REASON/Statistics2 Commented Apr 19, 2017 at 6:58

2 Answers 2

2

Use @Url.Action razor helper in order to obtain the correct path.

@Url.Action generates a fully qualified URL to an action method.

d3.json('@Url.Action("Statistics2","CANCEL_REASON")', function (data) {

Or simply

d3.json('/CANCEL_REASON/Statistics2', function (data) {
Sign up to request clarification or add additional context in comments.

1 Comment

@Url.Action won't be accessible if above code is written in .js file
1

Add a leading slash and you should be good to go:

d3.json("/CANCEL_REASON/Statistics2", function (data) { ... }

Then your path will relative to the root.

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.