Perhaps its my ignorance about how Razor/Html
helper works, hopefully someone from this forum will be able to throw light :)
I cant seem to get a simple lamda expression evaluated inside the html helper.
my razor view is strongly bound to the type "BrandViewModel
" and then the following code that is supposed to bind the list of brands(Brands property) to a drop down box
@{Html.DropDownListFor((x) => x.BrandId, x.Brands);}
fails w开发者_StackOverflow中文版ith the following error. The name 'x' does not exist in the current context
the intellisense does confirm those properties (BrandId and Brands) exist in the model and it shows the same when i type x.
Thanks in advance.
@Html.DropDownListFor((x) => x.BrandId, Model.Brands)
expression ends after first comma and @{Html.DropDownListFor((x) => x.BrandId, Model.Brands)}
won't show anything, because @{ }
is code block, equivalent to <% %>
.. to actually render it, you need to use just @
which is equivalent to <%: %>
or write it to output manually.
精彩评论