【问题标题】:How to fix No route error when using SurfaceController in Umbraco 7.1.8?在 Umbraco 7.1.8 中使用 SurfaceController 时如何修复无路由错误?
【发布时间】:2014-10-27 22:51:43
【问题描述】:

我想弄清楚如何让一个简单的联系表单 SurfaceController 工作。问题是,当我尝试导航到“联系我们”页面时,我得到“路由表中的路由与提供的值不匹配”。错误。

我的表面控制器:

namespace UmbracoSurface2.Controllers
{
    public class ContactFormSurfaceController : SurfaceController
    {
        public ActionResult Index()
        {
            return PartialView("ContactForm", new ContactFormViewModel());
        }
    }
}

我的 ContactForm 部分:

@model UmbracoSurface2.Models.ContactFormViewModel

<form>
    <div class="controls controls-row">
        @Html.TextBoxFor(m => m.Name)
        @Html.TextBoxFor(m => m.Email)
    </div>
    <div class="controls">
        @Html.TextAreaFor(m => m.Message, new { rows="5" })
    </div>
    <div class="controls">
        <button id="contact-submit" type="submit" class="btn btn-primary input-medium pull-right">Submit</button>
    </div>
</form>    

还有我的模板:

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
    Layout = "Master.cshtml";
}
@Html.Action("Index", "ContactFormController")

我的截屏视频和我发现的示例之间的一大区别是我使用的是 Visual Studio 2013,因此 ASP.NET 网站模板有一个更新版本的 MVC,我必须删除它才能获得 UmbracoCms NuGet包安装。我也试了一下,一开始不给项目添加MVC。

任何帮助/建议将不胜感激,

杰森

【问题讨论】:

  • SurfaceControllers 仅用于用户交互。例如,来自表单的帖子。您必须使用 RenderMvcController。 our.umbraco.org/documentation/Reference/Mvc/custom-controllers
  • 我不确定我所做的不是用户交互,特别是因为它是 Umbraco 团队使用的确切示例。无论如何,我已经在下面发布了解决方案。

标签: asp.net-mvc umbraco umbraco7


【解决方案1】:

好的,根据 Dan 在 Umbraco 论坛上的回答 here,我的问题是一个愚蠢的错误。模板中的@Html.Action 行应该是:

@Html.Action("Index", "ContactFormSurface")

杰森

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多