title: C# MVC Calling a method in different path using AJAX
body: <p>I have a HomeController in my ASP.NET MVC application in folder "Controllers". My View is in: "View/Home/Index.cshtml" (look at my figure below).</p>
  
  <p>I am using Ajax to get some json file every a few second. Problem is in Ajax URL, because I really don't know and didn't find, how to tell that property, that it has to go back a few folders and then find the HomeController.</p>
  
  <p>My Solution looks like this:</p>
  
  <p><a href="https://i.stack.imgur.com/0TMXv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0TMXv.png" alt="Solution of my MVC Application"></a></p>
  
  <p>Here is a method in my HomeController:</p>
  
  <pre><code>[HttpGet]
  public ActionResult GetRandomFeed()
  {
      Item i = ss.getRandomFeed();
      return Json(new { Source = i.Media.Source, Avatar = i.User.Avatar, Text = i.Text, Name = i.User.Name }, JsonRequestBehavior.AllowGet);
  }
  </code></pre>
  
  <p>My AJAX in the View:</p>
  
  <pre><code>setInterval(function () {
          $.ajax({
              type:        "GET",
              url:         '/HomeController.cs/GetRandomFeed', // Of course I have tried a lots of attempts in here
              contentType: "application/json;", // Not sure about this
              dataType:    "json",
              success: function (response) {
                  console.log("Success :)");
              },
              error: function() {
                  console.log("Error!");
              }
          });
      }, 2000);
  </code></pre>
  
  <p>All I want to get that JSON file (or can be even an array of strings) and use it in my Success function. It is a simple Slide Show and JSON contains the URLs that I want to show in the page every X seconds (just changing source of an image that is in that JSON file).</p>
  
  <p>I couldn't find anything like this. How to use that URL correctly OR found something similiar for WebForms but cannot use it in MVC.</p>