Click here to Skip to main content
14,865,088 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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: /rent/Save

Index.cshtml
JavaScript
@{
    ViewBag.Title = "Index";
}

<div class="row">
    @using (Html.BeginForm("Save", "rent", FormMethod.Post, new { id = "popupForm" }))
    {
        <div>
            <h1>CAR RENTAL</h1>
        </div>

        <div class="form-group">
            <label class="form-label">Car Number</label>
            <select class="form-control" id="carid" name="carid" placeholder="Car Number" required>
                <option>Please Select</option>
            </select>
        </div>

        <div class="form-group">
            <label class="form-label">Customer ID</label>
            <input type="text" id="custid" name="custid" class="form-control" placeholder="Customer ID" required />
        </div>

        <div class="form-group">
            <label class="form-label">Customer Name</label>
            <input type="text" id="customer_name" name="customer_name" class="form-control" placeholder="Customer Name" required />
        </div>

        <div class="form-group">
            <label class="form-label">Rental Fee</label>
            <input type="text" id="fee" name="fee" class="form-control" placeholder="Rental Fee" required />
        </div>

        <div class="form-group">
            <label class="form-label">Start Date</label>
            <input type="date" id="sdate" name="sdate" class="form-control" placeholder="Start Date" required />
        </div>

        <div class="form-group">
            <label class="form-label">End Date</label>
            <input type="date" id="edate" name="edate" class="form-control" placeholder="End Date" required />
        </div>

        <div class="form-group">
            <input type="submit" value="Save" class="btn btn-success" />
        </div>
    }
</div>

@section scripts
{

    <script src="~/Scripts/jquery-3.4.1.js"></script>
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/jquery.validate.js"></script>

    <script>

        Getcar();
        load();

        function load() {
            $("#custid").attr("disabled", "disabled");
            $("#customer_name").attr("disabled", "disabled");
            $("#fee").attr("disabled", "disabled");
            $("#sdate").attr("disabled", "disabled");
            $("#edate").attr("disabled", "disabled");
        }


        function Getcar() {
            $.ajax({

                type: 'GET',
                url: '/rental/Getcar',
                dataType: 'JSON',
                success: function (data) {
                    console.log(data);

                    for (var i = 0; i < data.length; i++) {
                        $("#carid").append($("<option/>", {
                            text: data[i].carnum
                        }));
                    }
                }
            });
        }

        $("#carid").change(function ()
        {
            availabile();

        });

        function availabile()
        {
            $.ajax({

                type: 'POST',
                url: '/rental/Getavail?carnum=' + $("#carid").val(),
                dataType: 'JSON',
                success: function (data) {
                    console.log(data)

                    var avail = data;

                    if (avail == "Yes")
                    {
                        $("#custid").removeAttr('disabled');
                        $("#customer_name").removeAttr('disabled');
                        $("#fee").removeAttr('disabled');
                        $("#sdate").removeAttr('disabled');
                        $("#edate").removeAttr('disabled');
                    }
                    else
                    {
                        $("#custid").attr("disabled", "disabled");
                        $("#customer_name").attr("disabled", "disabled");
                        $("#fee").attr("disabled", "disabled");
                        $("#sdate").attr("disabled", "disabled");
                        $("#edate").attr("disabled", "disabled");
                    }

                }
            });
        }

        Getcustomer()

        function Getcustomer() {

            $("#custid").keyup(function (e) {

                $.ajax({

                    type: 'POST',
                    url: '/rental/Getid?id=' + $("#custid").val(),
                    dataType: 'JSON',
                    success: function (data) {
                        console.log(data)

                        $("#customer_name").val(data)

                    }
                });
            });
        }
 
    </script>
}


RentalController.cs
C#
using SABLAWON_carrental.Models;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace SABLAWON_carrental.Controllers
{
    public class RentalController : Controller
    {
        carrentalEntities db = new carrentalEntities();
        // GET: Rental
        public ActionResult Index()
        {
            return View();
        }

        [HttpGet]
        public ActionResult Getcar()
        {
            var car = db.carregs.ToList();

            return Json(car, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public ActionResult Getid(int id)
        {
            var customers = (from s in db.customer where s.id == id select s.customer_name).ToList();

            return Json(customers, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public ActionResult Getavail(string carnum)
        {
            var caravailable = (from s in db.carregs where s.carnum == carnum select s.availability).FirstOrDefault();

            return Json(caravailable, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public ActionResult Save(rental rent)
        {
            if (ModelState.IsValid) 
            {
                db.rental.Add(rent);

                var car = db.carregs.SingleOrDefault(e => e.carnum == rent.carid);
                if (car == null)
                    return HttpNotFound("Car Number is Invalid");

                car.availability = "No";
                db.Entry(car).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");


            }

            return View(rent);
        }
    }
}


What I have tried:

I have tried renaming the rent in index and rentalcontroller. but it still doesnt work.
Posted
Updated 6-Jan-21 3:24am
v2
Comments
Richard MacCutchan 5-Jan-21 6:44am
   
"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."
The message is clear, you need to contact the site owners.

It's pretty obvious:
Quote:
Requested URL: /rent/Save


@using (Html.BeginForm("Save", "rent", FormMethod.Post, new { id = "popupForm" }))


But you called the controller "Rental", not "rent".
   
C#
@using (Html.BeginForm("Save", "Rental", FormMethod.Post, new { id = "popupForm" }))


Use this to fix the error
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900