Home
Do you use the URL as a navigation aid (aka redirect to the correct url if it is incorrect)?
  v3.0 Posted at 13/05/2013 4:35 PM by Damian Brady
Figure: Watch the URL working as a navigation aid

MVC gives us great URLs, but you need to help users navigate via the URL. If the user changes a URL, and the route parameters no longer match, you should correct them with a redirect.

public ActionResult Edit(string employeename, int id)
{
    var model = _repository.GetEmployee(id);

    // check for a parameter match and redirect if incorrect
    if (string.IsNullOrEmpty(employeename) || employeename != model.EmployeeName)
    {
        return RedirectToAction(
            "Edit", new { employeename = model.EmployeeName, id });
    }

    return View(model);
}
Figure: Good example - the comment says it all
Wordpress and Stack Overflow have URL formats that do this very well:

http://tv.ssw.com/3102/business-valueGood example: If the "business-value" part of the URL changes, the page will redirect to the correct location.

http://stackoverflow.com/questions/729921/settimeout-or-setinterval
Figure: Good example - If the "settimeout-or-setinterval" part of th eURL changes, the page will redirect to the correct location.

Related rules

    Do you feel this rule needs an update?

    If you want to be notified when this rule is updated, please enter your email address:

    Comments:

    Note: Social Media login for Yotpo is not working in IE or Safari, please use Chrome. We are waiting for Yotpo to fix it.