C# 从不同的文件夹C调用html部分#
我有以下目录结构:C# 从不同的文件夹C调用html部分#,c#,C#,我有以下目录结构: Public --mobile ----Views ------UK --------Recipes ----------ViewRecipePlain.cshtml // pull this --mobilePublic ----Views ------UK --------Recipes ----------ViewRecipe.cshtml // into this 我想从ViewRecipePlain.cshtml中调用ViewRecipePlain.cshtml
Public
--mobile
----Views
------UK
--------Recipes
----------ViewRecipePlain.cshtml // pull this
--mobilePublic
----Views
------UK
--------Recipes
----------ViewRecipe.cshtml // into this
我想从ViewRecipePlain.cshtml
中调用ViewRecipePlain.cshtml
在ViewRecipe.cshtml中,我正在尝试:
@Html.Partial("../../../../mobile/Views/UK/Recipes/ViewRecipePlain")
但是我得到了一个错误:
Cannot use a leading .. to exit above the top directory.
还有别的办法吗
更新
我还尝试:
@Html.Partial("~/mobile/Views/UK/Recipes/ViewRecipePlain.cshtml")
但会出现以下错误:
The partial view '~/mobile/Views/UK/Recipes/ViewRecipePlain.cshtml' was not found or no view engine supports the searched locations.
The following locations were searched:
~/mobile/Views/UK/Recipes/ViewRecipePlain.cshtml
如果DIR结构有影响,请更新它,使其更加准确,但对此表示怀疑。您可以使用视图的绝对路径:
@Html.Partial("~/mobile/Views/UK/Recipes/ViewRecipePlain.cshtml")
您也应该添加文件扩展名(请仔细查看答案)注意,当使用路径调用视图时,.cshtml扩展名是必要的。添加扩展名时同样会失败,但感谢您的提醒,我实际上认为可能有其他力量在阻止这一点,但我会接受这个答案,因为它是正确的,我认为这个问题可能有某种意义。嗯,这很奇怪。能否从.csproj文件所在的根文件夹开始发布整个项目结构?ViewRecipe之后在“主”和“普通”之间的切换是故意的还是打字错误?因为你说你试图调用“ViewRecipeMain”,但你所有的路径都是“ViewRecipePlan”。谢谢Sean,这确实是一个输入错误,已修复。