简体   繁体   English

Umbraco从API渲染强类型的部分内容

[英]Umbraco render strongly typed partial from api

What i'm trying to do: 我正在尝试做的是:

  • call an UmbracoApiController method from js 从js调用UmbracoApiController方法
  • do some server side processing 做一些服务器端处理
  • return a partial view with a custom model as a string 返回带有自定义模型的部分视图作为字符串

I've found helpful answers like: 我找到了有用的答案,例如:

http://our.umbraco.org/wiki/reference/code-snippets/razor-snippets/render-razor-scripts-for-emails-and-more/create-string-of-partial-view-for-emailing http://our.umbraco.org/wiki/reference/code-snippets/razor-snippets/render-razor-scripts-for-emails-and-more/create-string-of-partial-view-for-emailing

http://our.umbraco.org/forum/developers/api-questions/44916-615-Returning-Partial-View-as-string-to-JSON http://our.umbraco.org/forum/developers/api-questions/44916-615-Returning-Partial-View-as-string-to-JSON

But I can't figure out what Controller or ControllerContext to pass in since I'm not in a Razor view or RenderMvcController. 但由于我不在Razor视图或RenderMvcController中,因此我无法弄清楚要传递的Controller或ControllerContext。

Some help please? 请帮忙吗?

I normally call (with js, ajax, jquery) an Umbraco Surface controller and I pass my current page's node id. 我通常调用(使用js,ajax,jquery)Umbraco Surface控制器,然后传递当前页面的节点ID。 Then on server, I do: 然后在服务器上,我这样做:

var currentPage = Umbraco.TypedContent(myNodeIdParam);

From there I usually have enough context and I can return a partial view, passing it a model I want. 从那里,我通常有足够的上下文,并且我可以返回局部视图,并向其传递我想要的模型。

Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM