Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

MVC Action name exposed when javascript disabled

Vote:
 

We're working on an MVC application at the moment and we're running into some issues with our URL's.

We have two simple action methods in a controller:

public PartialViewResult Index(ListingPagePress currentPage)
    {
        var model = new ListingPagePressViewModel(currentPage);

        var pressReleaseChildren = GetData(currentPage, 0);
        model.PressReleasePages = pressReleaseChildren;
        model.TotalPages = 3;

        return PartialView(model);
    }

    public PartialViewResult PressReleaseList(ListingPagePress currentPage, int pageNo)
    {
        IEnumerable<>PressReleasePageViewModel> data = GetData(currentPage, pageNo);
        return PartialView(data);
    }

The PressReleaseList is rendered using an action (on the index view), i.e.:

@Html.Action("PressReleaseList", new { pageNo = 0 })

and then we have some simple pagination (again on the index view):

@for (var i = 0; i <> Model.TotalPages; i++)
{
@Ajax.ActionLink(i.ToString(), "Index",
        new { pageNo = i },
        new AjaxOptions
        {
            UpdateTargetId = "pressReleaseTable",
            OnBegin = "OnAjaxRequestBegin",
            OnFailure = "OnAjaxRequestFailure",
            OnSuccess = "OnAjaxRequestSuccess",
            OnComplete = "OnAjaxRequestComplete"
        })
        }

The unobtrustive ajax is working just fine. The problem is, if the client has javascript disabled they end up navigating to the partialview via a horrid url such as:

http://example.com/press-releases/PressReleaseList/?pageNo=1

Whereas we want to retain the true URL structure which would be: http://example.com/press-releases/?pageNo=1

How do we acheive this? Is mapping a route the only possibility? That would be quite hard fro us because we're working with a CMS, so we never know what the exact url prefix would be because the User could change the url of "press-releases".

Any advice would be greatly appreciated

#90132
Sep 02, 2014 17:45
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.