JavaScript does not exist page on Aspx

0

I have an application in ASPX and C #. Within the "Scripts" directory of the application, I have a js with the following code:

function RecuperaDados(valor){
  loadXMLDoc("../Views/Home/Contact.aspx?ID="+valor);
}

However, it is returning error "404 -Not Found", except that this "Contact" page is inside the "Home" directory that is within "Views". What can I be doing wrong?!

    
asked by anonymous 18.07.2014 / 14:01

1 answer

1

You are doing a HTTP request of type GET , the which means that specifying a file path is illegal and will not work.

Therefore, your loadXMLDoc function will not have another return until you specify an action.

What do you mean?

If you no longer have it, then create a method for Contact in your Home driver. Something like this:

public class HomeController : Controller
{
    [...]

    public ActionResult Contact(int id)
    {
        return View(id);
    }
}

Then, in your loadXMLDoc function, pass as parameter "/Home/Contact?id=" + valor , like this:

function RecuperaDados(valor){
  loadXMLDoc("/Home/Contact?id=" + valor);
}

What happened? What's the difference?

GET requests made with AJAX request for an equivalent type return - HTTP, in this case -, and you were dealing with a file address, which, as already said, will not work. So we've created an action on your controller Home , called Contact , to render your view Contact.aspx (you've already seen Razor ?) In response to a GET request in the HTTP protocol.

In this way, we have been able to solve your problem by specifying the AJAX request.

    
18.07.2014 / 14:25