Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Corné 1 post 21 karma points
    May 07, 2014 @ 16:01
    Corné
    0

    MVC ActionLink in the Umbraco request context?

    Hello everyone,

    I'm currently working with Umbraco 6.1.6 and some mvc views and controllers.
    What I try to do is the following:

    In my razor view I have the following line to create an actionlink:
    @Html.ActionLink("Klik to search...", "Search", "Search", new { SearchText = "searchterm" }, null)

    The actionlink fires the Search method of the SearchController (is a SurfaceController):

    public ActionResult Search(string SearchText)
    {
    if (String.IsNullOrEmpty(SearchText))
    {
    return RedirectToCurrentUmbracoPage();
    }

    SearchResult result = SearchManager.Instance.Search(SearchText);

            return View("SearchResults", result);
    }

    When I use an textbox and an submit button in an Html.BeginUmbracoForm this works well but when I use Html.ActionLink the RedirectToCurrentUmbracoPage throws an exception ( Cannot find the Umbraco route definition in the route values, the request must be made in the context of an Umbraco request ) and the results page does not use the specified style template. 

    How can I force the ActionLink to be made in the context of an Umbraco request?
    And does that bring back the styling like the other Umbraco pages?

    Thank you for your time!

Please Sign in or register to post replies

Write your reply to:

Draft