如何获取asp .net mvc2中lambda表达式的值?

发布于 2024-12-10 10:15:11 字数 495 浏览 4 评论 0原文

我有一个操作结果方法,它给出来自数据库的值,我将此值传递给视图,这些值将填充在文本框中,但我可以根据数据库的值选择单选按钮,例如如果该值是男性,则选择单选按钮,否则选择女性单选按钮。我已经编写了代码

<% 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遇见了你 2024-12-17 10:15:11

假设您此时已经可以访问模型,则根本不需要 lambda 表达式:

// Or whatever
<% if (model.Gender == Gender.Male) {%>

但是,我认为这不太可能是您打算使用 RadioButtonFor。我希望它能够选择正确的按钮来自动检查。

Assuming you've got access to the model at that point, you don't need the lambda expression at all:

// Or whatever
<% if (model.Gender == Gender.Male) {%>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文