2012-01-12 63 views
1

我有問題,要求用ajax 一個PartialView在我看來一切看起來找到了點,但錯誤出現這樣的:ASP.NET MVC 3與jQuery Ajax加載一個PartialView

請求URL:http:/ /本地主機:4530 /主頁/ ViewWorld 請求方法:GET 狀態代碼:404未找到

這裏是代碼:

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

我的控制器是這樣的:

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 
       ); 

誰能幫助我弄清楚爲什麼它不工作,感謝

+0

如果您在瀏覽器中打開URL(http:// localhost:4530/Home/ViewWorld),會發生什麼情況?你可以訪問任何其他行動? – Pbirkoff 2012-01-12 22:25:50

+0

你有沒有爲該行動設立的路線? – 2012-01-12 22:27:49

+0

錯誤顯示: 描述:HTTP 404.您正在查找的資源(或其某個依賴項)可能已被刪除,名稱已更改或暫時不可用。請檢查以下網址並確保它拼寫正確。 請求的URL:/首頁/ ViewWorld – Danny 2012-01-12 22:30:03

回答

1

你只是缺少一個斜槓 「/首頁/ ViewWorld」

+1

thx man,但是在添加斜槓後,錯誤仍然相同 – Danny 2012-01-12 22:38:37

+0

Tow要嘗試的事情。 1)包含一個數據:{}參數。 2)任何你不能做POST的原因? – 2012-01-12 22:47:44

+0

嗨,thx,問題修復了,錯誤是我的路由名仍然使用「Default」,假設把它改成其他。乾杯 – Danny 2012-01-12 23:02:54