ASP.NET MVC:HTML Helper Lambda 表达式无法识别变量
也许是我对 Razor/Html 帮助器如何工作的无知,希望这个论坛的某人能够阐明:)
我似乎无法在 html 帮助器内评估简单的 lamda 表达式。
我的剃刀视图强烈绑定到类型“BrandViewModel
”,然后应该将品牌列表(Brands 属性)绑定到下拉框的以下代码
@{Html.DropDownListFor((x) => x.BrandId, x.Brands);}
失败并出现以下错误。 名称“x”在当前上下文中不存在,
智能感知确实确认模型中存在这些属性(BrandId 和 Brands),并且当我键入 x 时,它显示相同的内容。
提前致谢。
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 with 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
表达式在第一个逗号后结束,并且
@{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.