default_noob_network
default_noob_network

Reputation: 1315

Why is my action result giving me a 404?

I have this controller:

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

when I do a GET for /Activity/Conference I get my partial view returned to me just fine. However when I GET /Activity/TradeShow I get a 404. Then, if I switch the code in this controller so that Conference appears before TradeShow, then I get the opposite results - a 404 for Conference and a working partial view for TradeShow.

Why is this? Seems like I am missing something fundamental here...

Here is the jQuery I am using for 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);
            }
        });
    });

Upvotes: 0

Views: 64

Answers (1)

user2771704
user2771704

Reputation: 6202

You can try to replace url in $.ajax({ to

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

and

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

Also if your ConferenceButton and TradeShowButton use ActionLinks in the View like this:

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

then you could use in the url this code:

 url: this.href,

Upvotes: 1

Related Questions