如何获取asp .net mvc2中lambda表达式的值?
我有一个操作结果方法,它给出来自数据库的值,我将此值传递给视图,这些值将填充在文本框中,但我可以根据数据库的值选择单选按钮,例如如果该值是男性,则选择单选按钮,否则选择女性单选按钮。我已经编写了代码
<% if(model=>model.Gender) {%>
<%= Html.RadioButtonFor(model => model.Gender, "Male", "Checked")%> Male
<%} else { %>
<%= Html.RadioButtonFor(model => model.Gender, "Female", "Checked")%> Female<%} %>
,但收到类似“无法将 lambda 表达式转换为类型'bool',因为它不是委托类型”的错误。请告诉我如何操作到检查性别的值并做出相应的选择。
I have a action result method where it gives values from the database and Iam passsing this values to the view and the values will be populated in the textboxes but i have radio button to be selected depending on the value of the database,example if the value is male then radiobutton as to be selected else radiobutton female aas to be selected.I have written the code
<% if(model=>model.Gender) {%>
<%= Html.RadioButtonFor(model => model.Gender, "Male", "Checked")%> Male
<%} else { %>
<%= Html.RadioButtonFor(model => model.Gender, "Female", "Checked")%> Female<%} %>
but Iam getting a error like "Cannot convert lambda expression to type 'bool' because it is not a delegate type" .Please tel me how to check the value of Gender and make selection accordingly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您此时已经可以访问模型,则根本不需要 lambda 表达式:
但是,我认为这不太可能是您打算使用
RadioButtonFor
。我希望它能够选择正确的按钮来自动检查。Assuming you've got access to the model at that point, you don't need the lambda expression at all:
However, I think it's unlikely that this is how you're meant to use
RadioButtonFor
. I'd expect it to be able to pick up the right button to check automatically.