what is the correct way to use Lambda in an ActionLink?
I'm trying this:
@Html.ActionLink(item.PageName, "ContentPage", new { id = item.PageName }, new { @title = item.ToolTip, item.Selected == 1 ? "class=selected" : "" })
but get an error for some reason,i can't figure out the correct syntax for it?
Thanks
I don't know ActionLink, but seems that in this piece of code:
you are declaring an anonimus type, whith a first field named "@title", but.... the second?!? Here we see an expression with a ternary operator, but it's return value isn't assigned to anything. You have to add an identifier and an assignement operator before "item.Selected":
If a value of class="" is not valid, you could try to can put the entire object in ternary operator, like this:
But likely this will not work: the ternary operator will not be able to determine the result type (the two anonimous type have different signature). The only other way is to instantiate first the right anonimous object, using the "var" type, and then pass it to the metod. In any case there are no lambda expressions here. You should tag your answer with "anonimous types" instead of "lambda".