将 Html.ActionLink() 与 ASP.NET MVC 结合使用Spark - 语法?

发布于 2024-08-19 18:03:33 字数 762 浏览 3 评论 0原文

全部, 在 NerdDinner 中使用 Spark 和 MVC 进行一些实验。普通/aspx 视图运行良好,而且我没有触及任何控制器代码,所以我很确定不是那样的。

<viewdata model="System.Collections.Generic.IEnumerable[[NerdDinner.Models.Dinner]]"/>
<set Title="'Upcoming Dinners'"/>
<content:main>

<li each="p in Model">
!{Html.ActionLink(p.Title, 'Details', 'Dinners')}
</li>

</content:main>

根据上面的代码,ActionLink 将呈现为 http://serverName/Controller/Action/ 这很好。当我尝试向我的操作方法提供 ID 时,我开始碰壁。据我从 Spark 示例文档中可以看出,我应该能够执行以下操作:

!{Html.ActionLink(p.Title, 'Details', 'Dinners', new {id = p.DinnerID} )}

但是,这会引发异常: “意外的标记'{'”

我希望这是我错过的一些愚蠢的东西......有什么建议吗?

All,
Doing some experimenting with Spark and MVC within NerdDinner. The normal/aspx view works well, and I haven't touched any of the controller code so I'm pretty sure it's not that.

<viewdata model="System.Collections.Generic.IEnumerable[[NerdDinner.Models.Dinner]]"/>
<set Title="'Upcoming Dinners'"/>
<content:main>

<li each="p in Model">
!{Html.ActionLink(p.Title, 'Details', 'Dinners')}
</li>

</content:main>

Given the code above, the ActionLink gets rendered as http://serverName/Controller/Action/
Which is good. I start hitting a wall when I try to provide the ID to my action method. As far as I can tell from the Spark sample docs, I should be able to do something like this:

!{Html.ActionLink(p.Title, 'Details', 'Dinners', new {id = p.DinnerID} )}

However, that throws an exception:
" unexpected token '{' "

I'm hoping it's something silly I'm missing...any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若能看破又如何 2024-08-26 18:03:33

我相信 Html.ActionLink 应该有另一个参数用于操作链接上的 HTML 属性。尝试:

!{Html.ActionLink(p.Title, 'Details', 'Dinners', new {id = p.DinnerID}, null )}

I believe there should be another parameter to Html.ActionLink for HTML attributes on the action link. Try:

!{Html.ActionLink(p.Title, 'Details', 'Dinners', new {id = p.DinnerID}, null )}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文