MVC Html.ActionLink 忽略 Controller 参数
我有一个包含以下代码的视图:
<h2><%= Model.Company.CompanyName %></h2>
<h3>Projects</h3>
<ul>
<%
foreach (Project p in Model.Company.Projects)
{
%>
<li><%= Html.ActionLink(p.ProjectName,"Details", "Projects", new {id=p.ProjectID,companyId=p.CompanyID}) %></li>
<%
}
%>
</ul>
<%= Html.ActionLink("Add Project", "Create", "Projects", new {id = Model.CompanyID}) %>
<br />
<h3>Users</h3>
我有一个 ProjectsController,但是当我运行该应用程序并单击“添加项目链接”时,它预计会转到 /Company/Create 而不是 /Projects/Create。我错过了什么吗?
I have a a view that has the following code:
<h2><%= Model.Company.CompanyName %></h2>
<h3>Projects</h3>
<ul>
<%
foreach (Project p in Model.Company.Projects)
{
%>
<li><%= Html.ActionLink(p.ProjectName,"Details", "Projects", new {id=p.ProjectID,companyId=p.CompanyID}) %></li>
<%
}
%>
</ul>
<%= Html.ActionLink("Add Project", "Create", "Projects", new {id = Model.CompanyID}) %>
<br />
<h3>Users</h3>
I have a ProjectsController but when I run the application and click on the Add Project Link it expects to go to /Company/Create instead of /Projects/Create. Am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在匹配需要第三个参数中的路由值的签名以及第四个中的 html 属性。添加另一个参数(可以为 null),您将获得签名它具有链接文本、操作、控制器、路由值和 html 属性。
You're matching the signature that expects the route values in the third parameter and the html attributes in the fourth. Add another parameter (null is ok) and you'll get the signature that has the link text, action, controller, route values, and html attributes.