MVC3布尔型用于表格+搜索 [英] MVC3 bools for tables + search

查看:64
本文介绍了MVC3布尔型用于表格+搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试访问数据库驱动的网站进行视频租赁

所以我的数据库中有两个表(电影和出租),
我在每个表"OnHire"中设置了一个列,其数据值为"bit"
选择了NULL值.

所以我可以使用所有的CRUD功能,但是...

当用户在租赁表中创建新的租赁记录并将"OnHire"设置为true
时 我正在尝试使用bool,然后将电影中的"OnHire"设置为true.

通过查看电影表让用户知道它是否正在租借
它告诉我我无法转换布尔型?要布尔,存在转换(您想念猫)吗?

Attempting to database driven website for video rentals

So I have two tables in my database (movie, and rental),
I have a column set in each table ''OnHire'' which has the data value of ''bit''
with NULL values selected.

So I have all the CRUD features working but...

When the user creates a new rental record in the rental table and turns ''OnHire'' to true
I am trying to use a bool which will then turn the ''OnHire'' in movies to true.

Allowing the user to know by looking at the movies table whether it is on hire or not
it is telling me i cant convert a type bool? to bool, a conversion exists(are you missing a cat)?

HttpPost]
        public ActionResult Create(Rental rentals)
        {
            try
            {
                // TODO: Add insert logic here
                _entities.AddToRentals(rentals);
                _entities.SaveChanges();

                Movie mov = new Movie();

                if (rentals.OnHire)
                {
                    mov.OnHire = true;
                }
                else
                {
                    mov.OnHire = false;
                }
      
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }



然后,我可能会在这里推我的运气,但如果成功了,我会做相反的事情,如果用户尝试租用已经租用的视频,则会抛出错误消息


如果(mov.OnHire)
{
//错误消息
}

有什么建议吗?

另外,在完成数据库的CRUD时,我是否希望实现搜索功能?

对任何教程人员有任何想法吗?

谢谢



Then I am probably pushing my luck here but if that is successfull I was going to do the opposite and throw an error message if the user tries to hire out a video already on hire


if (mov.OnHire)
{
//error message
}

Any suggestions?

Also on completion of the CRUD for database I was looking to implement a search feature?

Any ideas on any tutorials guys?

Thanks

推荐答案

我正在CRUD的create函数中尝试使用if语句.并通过引用数据库中的记录,我想使用bool更新记录...这可以在不使用实际sql编码的情况下进行吗?...请参见下文
I am trying to use an if statement inside the create function of CRUD. and by making a reference to the record in the DB i want to update a record using a bool...is this possible without using actual sql coding?...please see below


这篇关于MVC3布尔型用于表格+搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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