如何将数据作为0或1从MVC发送到数据库? [英] How to send data as either 0 or 1 to database from MVC?
本文介绍了如何将数据作为0或1从MVC发送到数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的MVC视图中添加一个下拉列表,它应该向数据库发送0或1。我应该在数据库中选择什么数据类型,以使其仅接受0或1.最重要的是如何在我的视图上创建该下拉列表。请帮助!!!
解决方案
您可以使用 tinyint [ ^ ]或 char [位 [ ^ ]类型。
以下是在视图中创建下拉列表的一些示例 -
DropDownList / Basic usage [ ^ ]
DropDownListFor with ASP.NET MVC [ ^
I want to add a drop-down to one of my view on MVC and it should send either 0 or 1 to database. What data-type should i select in database so as to make it to accept only 0 or 1. And most importantly how to create that drop-down on my view. Please help!!!
解决方案
You can use tinyint[^] or char[^] to store 0 and 1. An alternate could also be to use a bit[^] type.
Here are some examples on create a dropdownlist in a view -
DropDownList / Basic usage [^]
DropDownListFor with ASP.NET MVC[^]
这篇关于如何将数据作为0或1从MVC发送到数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文