2015-11-06 40 views
0

我有這樣的控制器:爲什麼我的行動結果給我一個404?

public class ActivityController : Controller 
    { 
     // GET: Activity 
     [HttpGet] 
     public ActionResult ProfessionalActivityForm() 
     { 
      return View(new Activity()); 
     } 
     public ActionResult TradeShow() 
     { 
      return PartialView("_AddTradeShow"); 
     } 
     public ActionResult InsertTradeShow(TradeShow TradeShow) 
     { 
      TradeShow.Insert(TradeShow); 
      return Content("Trade Show submitted successfully"); 
     } 
     public ActionResult Conference() 
     { 
      return PartialView("_AddConference"); 
     } 
     public ActionResult InsertConference(Conference Conference) 
     { 
      Conference.Insert(Conference); 
      return Content("Conference submitted successfully"); 
     } 
    } 

,當我做了一個/Activity/ConferenceGET讓我的部分觀點還給我就好了。然後,如果我切換此控制器中的代碼,以使會議出現在TradeShow之前,那麼我會得到相反的結果 - 會議404和TradeShow的工作分部視圖。

這是爲什麼?好像我失去了一些東西在這裏根本...

這裏是jQuery的我使用AJAX:

$('#ConferenceButton').on('click', function() { 
     $.ajax({ 
      type: "GET", 
      url: '/Activity/Conference', 
      success: function (data, textStatus, jqXHR) { 
       $('#partialViewContainer').html(data); 
       $('.focusMe').focus(); 
       //var top = $('.focusMe').offset().top; 
       //$("html, body").animate({ scrollTop: top }, 700); 
      } 
     }); 
    }); 
    $('#TradeShowButton').on('click', function() { 
     $.ajax({ 
      type: "GET", 
      url: '/Activity/TradeShow', 
      success: function (data, textStatus, jqXHR) { 
       $('#partialViewContainer').html(data); 
       $('.focusMe').focus(); 
       //var top = $('.focusMe').offset().top; 
       //$("html, body").animate({ scrollTop: top }, 700); 
      } 
     }); 
    }); 
+0

嘗試在你'$ .ajax'能指定'的dataType = 「HTML」'是默認智能猜測可以gess什麼來自控制器。 –

回答

1

您可以嘗試在$.ajax({更換url

url: '@Url.Action("Conference", "Activity")', 

url: '@Url.Action("TradeShow", "Activity")', 

此外,如果您的ConferenceButtonTradeShowButton個使用ActionLinks在查看這樣的:

@Html.ActionLink("Conference Button", "Conference", "Activity", null, new { id = "ConferenceButton" }) 

,那麼你可以在url使用此代碼:

url: this.href, 
相關問題