复选框asp.net的MVC

编程入门 行业动态 更新时间:2024-10-27 06:27:01
本文介绍了复选框asp的MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有两个选项

一个

<%= Html.CheckBox("postType", false, new { @id = item.int_PostTypeId.ToString() })%>

<input type="checkbox" name="postType" value="<%= item.int_PostTypeId.ToString() %>

1号问题:什么是复选框声明的这两个方法之间differenct。

1st question: what is differenct between these two method of check box declaration.

第二个问题:我们怎么能得到选中的复选框的价值?

2nd question: and how can we get value of checked checkbox?

推荐答案

如果你使用模型绑定使用Html.Checkbox(甚至更好的CheckBoxFor,在MVC2)。它会透明地处理复选框给你,你会读你的模型的布尔值。它将使东西比一个复选框更复杂(以避免产生于在后一个未经检查的复选框未发射的所有事实问题)。

Use the Html.Checkbox (or even better the CheckBoxFor, in MVC2) if you use a model binder. It will handle the checkbox transparently to you, and you will read the boolean value on your model. It will render something more complicated than a checkbox (to avoid the problem which arises from the fact that an unchecked checkbox is not transmitted at all in a POST).

相反,使用输入,如果你通过的FormCollection检索值:如果使用Html.Checkbox复合,你会在后(不是一般的价值,但是有两个testual值的字符串收到一些奇怪 (如真,假)。如果你使用的输入,你只需要检查是否存在该名称在后按键。

On the contrary, use the input if you retrieve the value via FormCollection: if you use the Html.Checkbox compound, you will receive something "strange" in the post (not the usual value, but a string with two testual values (like "true,false"). If you use the input, you just have to check if there exists that name in the post keys.

更多推荐

复选框asp.net的MVC

本文发布于:2023-10-12 01:37:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483393.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:复选框   asp   MVC   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!