如何在ASP.NET MVC中维护Html.CheckBox()的状态 [英] How to maintain state of Html.CheckBox() in ASP.NET MVC

查看:92
本文介绍了如何在ASP.NET MVC中维护Html.CheckBox()的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的MVC应用程序中有两个复选框,它们都是布尔/位字段. "NotifyEmail"和"NotifySMS".

I have two checkboxes in my MVC app which are both boolean / bit fields. "NotifyEmail" & "NotifySMS".

每当我发回服务器并发生错误时,即使我设置尝试的值,复选框的状态也会消失.

Whenever I post back to the server and an error occurs, the state of the checkbox is gone event though I set attempted values.

推荐答案

为什么不这么简单?

<%=Html.CheckBox("AgreeToRules", (Request.Form["AgreeToRules"] ?? string.Empty).Contains("true"))%>

这篇关于如何在ASP.NET MVC中维护Html.CheckBox()的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆