views:

24

answers:

1

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?

A: 

I believe it's there primarily to allow us to pass in multiple route values:

/blogs/[username]/archive/[year]/[month]/[day]/[title]

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

Although, I admit that it's tedious to have to instantiate a new object when all you're defining is a measly ID value. Unfortunately, the code you've written is the most concise it gets at this point.

Derek Hunziker

related questions