使用@ Html.Partial

时间:2013-09-06 07:43:09

标签: asp.net-mvc

我需要在不同的页面上添加相同的菜单,我厌倦了使用@Html.Partial
我创建了部分视图_ProjectMenu.cshtml

<ul class="sub-menu">
    <li>@Html.ActionLink(Resources.Global.Home_Menu_Project_AssociationManagement, "AssociationManagement", "Projects")</li>
    <li>@Html.ActionLink(Resources.Global.Home_Menu_Project_WarehouseAndInventory, "WarehouseAndInventory", "Projects")</li>
    <li>@Html.ActionLink(Resources.Global.Home_Menu_Project_ElectronicDocumentManagement, "ElectronicDocumentManagement", "Projects")</li>
    <li>@Html.ActionLink(Resources.Global.Home_Menu_Project_Medicine, "Medicine", "Projects")</li>
    <li>@Html.ActionLink(Resources.Global.Home_Menu_Project_BankingSector, "BankingSector", "Projects")</li>
    <li>@Html.ActionLink(Resources.Global.Home_Menu_Project_Insurance, "Insurance", "Projects")</li>
    <li>@Html.ActionLink(Resources.Global.Home_Menu_Project_Websites, "Websites", "Projects")</li>
    <li>@Html.ActionLink(Resources.Global.Home_Menu_Project_WebApplication, "WebApplication", "Projects")</li>
    <li>@Html.ActionLink(Resources.Global.Home_Menu_Project_DataWarehouse, "DataWarehouse", "Projects")</li>
    <li>@Html.ActionLink(Resources.Global.Home_Menu_Project_MobileApplications, "MobileApplications", "Projects")</li>
    <li>@Html.ActionLink(Resources.Global.Home_Menu_Project_TrafficManagement, "TrafficManagement", "Projects")</li>
    <li>@Html.ActionLink(Resources.Global.Home_Menu_Project_LearningSystems, "LearningSystems", "Projects")</li>
    <li class="sector">@Html.ActionLink(Resources.Global.Home_Menu_Project_Sector, "Sector", "Projects")</li>
</ul>

然后我在我的页面上添加了这段代码

<div class="span4">
    @Html.Partial("_ProjectMenu")
</div>

但它不起作用。
我想我需要在控制器中添加一些代码,但我不知道该怎么做?

UPD 我将部分视图文件放在Shared文件夹中 我得到了这个例外 enter image description here

1 个答案:

答案 0 :(得分:3)

您的观点名为 _ProjectMenu ,您正在引用 _ProjectsMenu