0

I'm using ASP.NET MVC 4 C Sharp and I have this error

Server Error in '/' Application.

The resource cannot be found. 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: /ClerkBooking/ConfirmBooking/22

In my controller I have:

  [HttpPost]
    [ValidateAntiForgeryToken]
    [Authorize(Roles = "Booking Clerk")]
    public ActionResult ConfirmBooking(int id = 0)
    {
       if (ModelState.IsValid)
       {
            //Find the booking
            Booking booking = db.Bookings.Find(id);

            //Get RoomID of Preferred Room.
            int roomId = Convert.ToInt32(db.Rooms.Find(booking.PreferredRoom));

            //Set RoomID of Booking.
            booking.RoomId = roomId;

            //Save Changes.
            db.SaveChanges();
        }

        return View("Index");
    }

So im not sure why its not finding the method even though its in the correct place. Any help would be great! Thanks!

4
  • And my link to it is: <td>@Html.ActionLink("Confirm Booking", "ConfirmBooking", new {id = booking.BookingId})</td> Commented Dec 12, 2013 at 15:48
  • 1
    Most importantly: Does your ConfirmBooking controller have an Index view? Commented Dec 12, 2013 at 15:50
  • something is not right there in your ActionLink. I don't believe your controller name or method name is Confirm Booking. 2 separate words there Commented Dec 12, 2013 at 15:50
  • replace int id = 0 with int id Commented Dec 12, 2013 at 16:04

3 Answers 3

2

Your action link @Html.ActionLink("Confirm Booking", "ConfirmBooking", new {id = booking.BookingId}) is going to make a GET request, but you put an [HttpPost] attribute on the action.

You'll probably want to make the link a button inside of a form post instead of an action link.

Here's an example:

@using (Html.BeginForm("ConfirmBooking", "ClerkBooking", new { id = booking.BookingId }))
{
    <input type="submit" value="Confirm Booking" />
}
Sign up to request clarification or add additional context in comments.

Comments

0

Make sure your controller is called "ClerkBooking" and remove the [HttpPost] decoration from the method.

1 Comment

I wouldn't recommend that. HttpPost should be used for actions that modify data.
0

Are adding your AntiForgeryToken to your html file?

@using (Html.BeginForm("Manage", "Account")) {
    @Html.AntiForgeryToken()
}

If not then probably asp.net mvc is blocking to reach your controller.

Also do not forget to check your Global.asax with the parameters:

   public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

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

        }

Otherwise you have to declare your id object from outside.

 $.ajax("/ClerkBooking/ConfirmBooking/?id=22", {
            type: "POST",
            contentType: "application/json; charset=utf-8",
            success: function (result) {

               //Do Something

                }
            }
        }).fail(function () {
                         //Do Something
        });

1 Comment

AntiForgeryToken confirmation happens later on in the request, it wouldn't cause a 404.

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.