如何在Umbraco控制器中调用一个动作?

时间:2017-07-06 07:41:43

标签: asp.net-mvc model-view-controller controller umbraco umbraco7

我创建了一个带有别名DocumentType的Umbraco Personal并创建了一个继承

的控制器
  

Umbraco.Web.Mvc.RenderMvcController

我添加了两个Action,一个是默认操作,另一个是Test

如何从Test控制器触发Personal操作?

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";
    }
}

当我按下这样的网址时:localHost/personal/test显示:

  

没有umbraco文档与网址'/ test'匹配。

哪个是对的,我怎么称呼它?

1 个答案:

答案 0 :(得分:2)

我会这样做

[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);
}

请参阅此博客文章,了解此代码段所在的完整背景信息。

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