ServiceStack剃须刀默认页面 [英] ServiceStack razor default page

查看:156
本文介绍了ServiceStack剃须刀默认页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有2页


  1. /NotADefault.cshtml

/Views/Default.cshtml

问题1。

现在我运行它,页 A 总是被隐式调用作为启动时的默认页面不管我的名字。
结果页 B 才会被调用时,我明确地调用本地主机/查看/默认。如何让网页 B (一个在浏览文件夹中)我的默认页?

Now I run it, page A always gets called implicitly as start-up default page no matter what I name it.
Page B will only be called when I explicitly call localhost/View/Default. How do I make page B (the one in View folder) my default page?

问题2。

我也有 NotADefaultService.cs DefaultService.cs 。我给每个页面服务类在后面。然而,当页 A 被称为 NotADefaultService.cs 不会被调用。只有 DefaultService.cs 被调用时,页面 B 被称为...

I also have NotADefaultService.cs and DefaultService.cs. I give each page a Service class at the back. However, when page A is called NotADefaultService.cs never gets called. Only DefaultService.cs gets called when page B is called...

我的观察是,只有在页面视图文件夹会得到他们的后端服务类的工作。的视图之外文件夹这是行不通的。

My observation is that only the pages in the View folder will get their back-end service class working. Outside of View folder it doesn't work.

结合Q1和Q2。

我如何:

选项1。获取后台服务类根据 /根之外的视图文件夹中的工作?

Option 1. get the backend service class working under / root outside "View" folder?

选项2 指定 /View/Default.schtml 作为我在启动时默认,其中服务类可击?

Option 2. appoint /View/Default.schtml as my default at start-up where the service class can be hit?

推荐答案

ServiceStack


    存在内的
  • 剃须刀页/查看/ 文件夹被称为查看网页

  • 存在其他任何地方剃刀页面被称为内容网页

  • Razor Pages that exist within the /Views/ folder are called View Pages
  • Razor Pages that exist anywhere else are called Content Pages

它们之间的区别是,查看网页是用于提供HTML重新presentations(又名意见)剃刀意见在大致相同的服务方法查看页面的MVC控制器工作。

The difference between them is that View Pages are Razor views that are used to provide the HTML representations (aka views) for services in much the same way View Pages work for MVC Controllers.

查看网页的不能被直接调用,这是内容网页,其中的角色只能被直接调用,即上下文之外服务(或重定向到,从一个服务)。

View Pages cannot be called directly, that's the role of Content Pages, which can only be called directly, i.e. outside the context of a service (or redirected to, from a service).

剃刀Rockstars的,内容页的例子包括:

In Razor Rockstars, examples of Content Pages include:


  • /明星/死亡/科班/ 它调用的<一个href=\"https://github.com/ServiceStack/RazorRockstars/blob/master/src/RazorRockstars.WebHost/stars/dead/Cobain/default.cshtml\"相对=nofollow> /明星/死亡/科班/ default.cshtml 内容页

  • / TypedModelNoController 它调用的<一个href=\"https://github.com/ServiceStack/RazorRockstars/blob/master/src/RazorRockstars.WebHost/TypedModelNoController.cshtml\"相对=nofollow> / TypedModelNoController.cshtml 内容页

  • /stars/dead/cobain/ which calls the /stars/dead/Cobain/default.cshtml Content Page
  • /TypedModelNoController which calls the /TypedModelNoController.cshtml Content Page

虽然示例查看网页包括:


  • /摇滚明星其中匹配/摇滚明星在<路线href=\"https://github.com/ServiceStack/RazorRockstars/blob/master/src/RazorRockstars.WebHost/RockstarsService.cs\"相对=nofollow> / RockstarsService.cs 并因为 [默认视图(Rockstars的)] 属性,使用<一个href=\"https://github.com/ServiceStack/RazorRockstars/blob/master/src/RazorRockstars.WebHost/Views/Rockstars.cshtml\"相对=nofollow> / Rockstars.cshtml 查看页

  • /rockstars which matches the /rockstars route on the /RockstarsService.cs and because of the [DefaultView("Rockstars")] attribute, uses the /Rockstars.cshtml View Page

有关内容网页 default.cshtml 是一个文件夹的索引页。因此,要设置为根 / 路径的默认页面,创建一个 /default.cshtml 页。这样的一个例子是 /default.cshtml 的主页在重用的演示使用。

For Content Pages the default.cshtml is the index page for a folder. So to set a default page for the root / path, create a /default.cshtml page. An example of this is /default.cshtml home page used in the Reusability demo.

如果你想使用一个视图页面为主页,你可以设置默认重定向到它通过添加APPHOST配置:

If you want to use a view page as the Home page, you can set the default redirect to it by adding the AppHost config:

SetConfig(new HostConfig { 
   DefaultRedirectPath = "/home"
});

这将调用的服务匹配 /家居将使用最适当的查看页面根据所设定的规则路线< A HREF =htt​​p://razor.servicestack.net/相对=nofollow>剃刀Rockstars的页。

Which would call a service matching the /home route that will use the most appropriate View Page based on the rules laid out in the Razor Rockstars page.

这篇关于ServiceStack剃须刀默认页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆