I have an asp.net 4.6.1, mvc 5 webapp with attribute routing. The code is

public ActionResult Details(int? id, string title)
    if (id == null)
            return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
    Cars car = db.Cars.Find(id);
    if(title == null || title.ToLower()!= ParseTitleToUrlVersion(car.Title.ToLower()))
              return Redirect("/cars/" + id + "/" + ParseTitleToUrlVersion(questions.Title));
    If(cars == null)
              // return not found;
    Return View(car);

The details view successfully renders the details of the car with id = 3 for these url's


but when i try to browse this url which doesn't specify the title


it says that it could not find the resource. I want it also to redirect to the url with correct title. The code also says if title is null, redirect it to the first url. For example, these two url's give the same page




I also want that when the second url is browsed, it redirects to the correct url. Kindly help in finding where is the error in my code.

Related posts

Recent Viewed