Tom*_*Tom 5 razor servicestack
我想在剃刀页面中包含类型化模型子页面。我知道SS和MVC剃刀不一样。实现的方法可能会有所不同。
到目前为止,这就是我所想出的(看起来很难看,我知道......):
//this is somewhere in your default.cshtml
@{
//grab your service from Ioc
using(var service = Get<RockstarsService>()) {
//execute the service to get a response
var resp = service.Get(new Rockstars());
//call the partial razor page Rockstar.cshtml
<p>@Html.Partial("Rockstars",resp)</p>
//or @Html.Partial("Rockstars") will do, seems like the resp is cached anyway
//or @Include("Rockstars",resp) will work, too.
}
}
Run Code Online (Sandbox Code Playgroud)
此解决方案适用于类型化模型子页面,前提是该子页面不包含任何 html 帮助程序。
但是,如果子页面有 html 帮助程序,例如
@Html.Label("sometag") //PROBLEM HERE <---------------------
Run Code Online (Sandbox Code Playgroud)
或者
@Html.TextBox("name","text") //PROBLEM HERE <---------------------
Run Code Online (Sandbox Code Playgroud)
然后它会抛出服务器错误:
Server Error in '/' Application.
Could not execute partial: Rockstars, model: RazorRockstars.WebHost.RockstarsResponse
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Could not execute partial: Rockstars, model: RazorRockstars.WebHost.RockstarsResponse
Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace: [InvalidOperationException: Could not execute partial: Rockstars, model: RazorRockstars.WebHost.RockstarsResponse]
ServiceStack.Razor.Templating.TemplateService.RenderPartial(T model, String name) +333
ServiceStack.Razor.RazorFormat.RenderPartial(String pageName, Object model, Boolean renderHtml, IHttpRequest httpReq) +433
ServiceStack.Html.HtmlHelper.Partial(String viewName, Object model) +117
CompiledRazorTemplates.Dynamic.fdbaecbccda.Execute() +454
ServiceStack.Razor.Templating.TemplateService.ExecuteTemplate(T model, String name, String defaultTemplatePath, IHttpRequest httpReq, IHttpResponse httpRes) +457
ServiceStack.Razor.RazorFormat.ExecuteTemplate(T model, String name, String templatePath, IHttpRequest httpReq, IHttpResponse httpRes) +117
ServiceStack.Razor.RazorFormat.ProcessRazorPage(IHttpRequest httpReq, ViewPageRef razorPage, Object dto, IHttpResponse httpRes) +142
ServiceStack.Razor.RazorHandler.ProcessRequest(IHttpRequest httpReq, IHttpResponse httpRes, String operationName) +535
ServiceStack.WebHost.Endpoints.Support.EndpointHandlerBase.ProcessRequest(HttpContext context) +264
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +341
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
Run Code Online (Sandbox Code Playgroud)
(Bloody VS Razor 断点不起作用,因为它是纯粹的 SS,而不是 MVC 项目。这让我很难查明问题......但那是另一个故事)
任何帮助都会很棒。
| 归档时间: |
|
| 查看次数: |
322 次 |
| 最近记录: |