Html.RenderPartial 给我奇怪的过载错误?
我制作了一个名为 _Test.cshtml 的测试部分页面,并将其放在与将调用它的视图相同的目录中,如下所示:
<div>hi</div>
在调用 cshtml 视图中,我简单地输入
@Html.RenderPartial("_Test")
:我的错误:
CS1502:最好的重载方法 匹配 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' 有一些无效参数
我也尝试了完整路径,但结果相同。
我很困惑为什么会这样,我想我错过了一些简单的东西?
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>
And in the calling cshtml view, I simply put:
@Html.RenderPartial("_Test")
Which gives me the error:
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您收到此错误是因为
Html.RenderXXX
帮助程序返回 void - 它们没有任何可返回的内容,因为它们直接* 写入内容以响应。你应该像这样使用它们:还有 Html.Partial 帮助器,它将与你的语法一起使用,但我不建议使用它,除非你必须这样做,因为性能(它首先将给定的部分视图组合成字符串,然后父视图将其放入响应中*)。
* 这并不完全正确,它们实际上被渲染到 ViewContext.Writer 中,一旦整个页面被渲染和组合,整个事情就会进入响应
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: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*).
* 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