gpt4 book ai didi

Umbraco SurfaceController 与 RenderMvcController

转载 作者:行者123 更新时间:2023-12-03 22:36:37 25 4
gpt4 key购买 nike

目的是什么,什么时候应该使用 SurfaceController 和 RenderMvcController?似乎我无法用 SurfaceController 做任何事情,而我不能用 RenderMvcController 做任何事情。例如,我正在专门考虑处理表单提交。使用 RenderMvcController 我可以:

public class HomeController : RenderMvcController
{
private IUmbracoMapper _umbracoMapper;

public HomeController()
{
_umbracoMapper = new UmbracoMapper();
}

[HttpGet]
public ActionResult Home()
{
HomeViewModel viewModel = new HomeViewModel();

_umbracoMapper.Map(CurrentPage, viewModel);

return CurrentTemplate(viewModel);
}

[HttpPost]
public ActionResult Home(HomeViewModel viewModel)
{
// Handle form submission
}
}

这对我来说似乎更符合 MVC,特别是因为我可以使用像 UmbracoMapper 这样的包将当前 Umbraco 节点映射到 View 模型并将其传递给我的 View ?为什么以及何时应该使用 SurfaceController?

如果我愿意的话,我可以使用 RenderMvcController 来劫持给定节点的每条路由,让我对我的应用程序有更多的控制,更像是一个纯粹的 ASP.NET MVC 应用程序。这是一件好事吗?

最佳答案

来自官方文档:

表面 Controller

A SurfaceController is an MVC controller that interacts with the front-end rendering of an UmbracoPage. They can be used for rendering Child Action content, for handling form data submissions and for rendering Child Action macros. SurfaceControllers are auto-routed meaning that you don't have to add/create your own routes for these controllers to work.



来源: http://our.umbraco.org/documentation/Reference/Templating/Mvc/surface-controllers

自定义 Controller

By default all of the front end routing is executed via the Umbraco.Web.Mvc.RenderMvcController Index Action which should work fine for most people. However, in some cases people may want complete control over this execution and may want their own Action to execute. Some reasons for this may be: to control exactly how views are rendered, custom/granular security for certain pages/templates or to be able to execute any custom code in the controller that renders the front end. The good news is that this is completely possible. This process is all about convention and it's really simple!



来源: http://our.umbraco.org/documentation/Reference/Templating/Mvc/custom-controllers

这有帮助吗?不过你是对的,我认为 Surface Controller 的唯一真正区别是自动路由。

西蒙

关于Umbraco SurfaceController 与 RenderMvcController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27515659/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com