0

I'm following the NerdDinner ASP.Net MVC tutorial and I have the following line of code:

<%= Html.ActionLink("Edit Dinner", "Edit", new { id = Model.DinnerID}) %> |
<%= Html.ActionLink("Delete Dinner", "Delete", new { id = Model.DinnerID }) %>        

What I don't understand is why the third parameter of the ActionLink requires a new {} command. Can someone please elaborate?

Why does it need to create a new {}, instead of just passing the ActionLink the Model.DinnerID without instancing it to another variable?

4

1 回答 1

0

我相信它主要是为了让我们可以传入多个路由值:

/blogs/[用户名]/archive/[年]/[月]/[日]/[标题]

<%= Html.ActionLink("Blog", "Details", new { username = Model.Username, year = Model.year, month = Model.month, day = Model.day, title = Model.title }) %>

虽然,我承认当您定义的只是一个微不足道的 ID 值时,必须实例化一个新对象是很乏味的。不幸的是,您编写的代码是目前最简洁的。

于 2010-07-26T22:57:49.180 回答