Html.RenderPartial给我怪过载错误? [英] Html.RenderPartial giving me strange overload error?

查看:223
本文介绍了Html.RenderPartial给我怪过载错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了名为 _Test.cshtml 测试部分页,并把它放在同一目录下我认为,将调用它,那就是:

I made a test partial page named _Test.cshtml and put it in the same directory as my view that will be calling it, here it is:

<div>hi</div>

和在调用CSHTML看法,我简单地说:

And in the calling cshtml view, I simply put:

@Html.RenderPartial("_Test")

这给我的错误:

CS1502:最好的重载方法
  难挡
  System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)'
  有一些无效参数

CS1502: The best overloaded method match for 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' has some invalid arguments

我也尝试过同样的结果的完整路径。

I have also tried the full path with the same result.

我,为什么这是演戏这条路很迷茫,我想我失去了一些东西简单?

I am very confused as to why this is acting this way, I assume I am missing something simple?

推荐答案

由于 Html.RenderXXX 助手返回void您收到此错误 - 他们什么都没有回来,因为他们直接写*的东西的反应。你应该使用它们像这样:

You are getting this error because Html.RenderXXX helpers return void - they have nothing to return because they are writing stuff directly* to response. You should use them like this:

@{ Html.RenderPartial("_Test"); }

还有Html.Partial帮手,可以使你的语法的工作,但是,除非你有,因为性能(首次给出组成部分观点为字符串,然后父视图所说的那样我不建议使用它为响应*)。

There is also Html.Partial helper, which will work with your syntax, but I'd not recommend using it unless you have to, because of performance (it first composes given partial view into string, and then parent view puts it into response*).

*这是不完全正确,他们实际上是被渲染成ViewContext.Writer,一旦整个页面呈现和组成,整个事情去回应

* this is not entirely true, they are actually being rendered into ViewContext.Writer and once whole page is rendered and composed, the whole thing goes to response

这篇关于Html.RenderPartial给我怪过载错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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