1

I got problem to request a PartialView using ajax In my point of view everything looks find, but error show up like:

Request URL:http://localhost:4530/Home/ViewWorld Request Method:GET Status Code:404 Not Found

Here are the codes:

$.ajax({
        url: "Home/ViewWorld", //'@Url.Action("viewWorld", "Home")',
        type: "GET",
        dataType: "html",
        success: function (e) {
            alert(e);
    },
        error: function (error) {
            alert(error[0]);
    }
    });

My controller look like this:

public class HomeController : Controller
{
    //
    // GET: /Index/

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

    [HttpGet]
    public ActionResult ViewWorld()
    {
        return PartialView("_ContactMe");
    }

}

Global.asax:

routes.MapRoute( "Default", // Route name 
                "{controller}/{action}/{id}", // URL with parameters 
                new { controller = "Home", 
                      action = "ViewWorld", 
                      id = UrlParameter.Optional } // Parameter defaults 
                );

Can anyone help me to figure out why it does not works, thanks

4
  • What happends if you open the URL (localhost:4530/Home/ViewWorld) in your browser? Can you access any other Action? Commented Jan 12, 2012 at 22:25
  • do you have a route set up for that action ? Commented Jan 12, 2012 at 22:27
  • The error show up: Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. Requested URL: /Home/ViewWorld Commented Jan 12, 2012 at 22:30
  • I have set up in the Global: routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "ViewWorld", id = UrlParameter.Optional } // Parameter defaults ); Commented Jan 12, 2012 at 22:34

1 Answer 1

1

You are just missing a forward slash: "/Home/ViewWorld"

Sign up to request clarification or add additional context in comments.

3 Comments

Tow things to try. 1) Include a data: {} parameter. 2) Any reason you can't do a POST?
Hi man, thx, problem fixed, the error is my route name is still using "Default", suppose to change it to other. Cheers
I just noticed your original url has a lower case "v" - it should be '@(Url.Action("ViewWorld","Home"))' - I think this is a safer syntax than the /Home/ViewWorld. HTH

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.