简体   繁体   English

通过@Helper在视图中渲染部分视图以调用部分视图

[英]Render partial View in a View Via @Helper to call the partial

OK So I'm just messing around, as I discovered @helpers as placed in the App_Code Folder for MVC. 好的,所以我只是在搞乱,因为我发现@helpers位于MVC的App_Code文件夹中。 my Index.cshtml, yes Razor beautifully calls my helper "MasterPersonHelper.cshtml" 我的Index.cshtml,是的,Razor很好地称我的助手为“ MasterPersonH​​elper.cshtml”

@MasterPersonHelper.ReturnPersonList();

However If I place the call to the helper method in a partial View, (just playing around to see what happens ) and yes that partial is in the shared folder. 但是,如果我将对helper方法的调用放置在局部视图中(只是四处浏览以查看发生了什么),是的,该局部部分位于共享文件夹中。

Then attempt to call the partial to render the results of the helper from my index.cshtml @Html.Partial("ListPerson"); 然后尝试从我的index.cshtml @ Html.Partial(“ ListPerson”);调用局部函数来呈现帮助程序的结果。

instead of directly calling the helper VS claims it cant find the partial but it assuredly lists the path it is located at. VS声称没有找到局部,但没有直接调用助手VS,而是肯定列出了它所在的路径。 " And can't see it" “看不见”

I believe it just cant call the helper from the partial since the helper is out in the app_Code Directory since its printing the correct path of the partial in its error. 我相信它无法从部分调用帮助器,因为该帮助器在app_Code目录中不存在,因为它在错误中打印了部分的正确路径。

I researched this & just figured I'd ask or inform whatever.. Thanks 我对此进行了研究,并想出了要问或告知的内容。

Sorry I had pretty pictures but I'm a noob here so yea No Go 抱歉,我有漂亮的照片,但是我在这里是菜鸟,所以

SUMMARY View calls helper = beautiful 摘要查看呼叫助手=美丽

View (In Views\\Controllername Folder) calls partial ( In Shared Folder ) 视图(在Views \\ Controllername文件夹中)调用部分(在共享文件夹中)
containing call to helper (in App_Code directory) = FAIL !!!! 包含对助手的调用(在App_Code目录中)= FAIL !!!!

with misleading error. 误导性错误。

Peace 和平

Can you try adding a "using" to the top of your partial? 您可以尝试在局部的顶部添加“使用”吗? For example: 例如:

@using MvcApplication1.Controllers.Helpers

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

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