[英]Why is my action result giving me a 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/Conference
做一個GET
,我的局部視圖就好了。 但是,當我GET
/Activity/TradeShow
我得到一個404。然后,如果我在此控制器中切換代碼,使Conference出現在TradeShow之前,則得到相反的結果-Conference的404和TradeShow的工作局部視圖。
為什么是這樣? 似乎我在這里缺少基本的東西...
這是我用於ajax的jQuery:
$('#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);
}
});
});
你可以嘗試更換url
在$.ajax({
到
url: '@Url.Action("Conference", "Activity")',
和
url: '@Url.Action("TradeShow", "Activity")',
同樣,如果您的ConferenceButton
和TradeShowButton
在視圖中使用ActionLink像這樣:
@Html.ActionLink("Conference Button", "Conference", "Activity", null, new { id = "ConferenceButton" })
那么您可以在url
使用以下代碼:
url: this.href,
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.