Search code examples
asp.net-mvcmodel-view-controllercontrollerumbracoumbraco7

How To call An Action In Umbraco Controller?


I created an Umbraco DocumentType with the alias Personal and created a controller that inherits

Umbraco.Web.Mvc.RenderMvcController

I added two Actions, one is the default action and the other is called Test.

How can I fire the Test Action from the Personal controller?

public class PersonalController : Umbraco.Web.Mvc.RenderMvcController
{
    // GET: Personal
    public override ActionResult Index(RenderModel model)
    {
        return base.Index(model);
    }

    public String Test(RenderModel model)
    {
        return "fff";
    }
}

When I put the url like this: localHost/personal/test it shows:

No umbraco document matches the url '/test'.

Which is right, so how can I call it?


Solution

  • I would do it like this

    [HttpPost]
    public ActionResult SubmitSearchForm(SearchViewModel model)
    {
        if (ModelState.IsValid)
        {
            if (!string.IsNullOrEmpty(model.SearchTerm))
            {
                model.SearchTerm = model.SearchTerm;
                model.SearchGroups = GetSearchGroups(model);
                model.SearchResults = _searchHelper.GetSearchResults(model, Request.Form.AllKeys);
            }
            return RenderSearchResults(model.SearchResults);
        }
        return null;
    }
    
    public ActionResult RenderSearchResults(SearchResultsModel model)
    {
        return PartialView(PartialViewPath("_SearchResults"), model);
    }
    

    See this blog post for the full context behind where this code snippet came from.

    http://www.codeshare.co.uk/blog/how-to-search-by-document-type-and-property-in-umbraco/