mvc在模型类中使用bool更改db中的属性 [英] mvc using bool in model class to change property in db

查看:98
本文介绍了mvc在模型类中使用bool更改db中的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计们...所以即时通讯使用mvc3为出租系统创建数据库网站.

在我的模型文件夹中的Rental.cs中,它就像..

Hey guys...So im using mvc3 to create a database website for a rental system.

in my rental.cs in my model folder it goes like..

<pre lang="c#">public class Rental
    {
        public int RentalID { get; set; }

        public int CustomerID { get; set; }

        public int MovieID { get; set; }

        public bool? OnHire { get; set; }
       // public static bool test;
//On another note i had to take out the 'static' in public statick bool? onhire
as it threw an error when I tried to load the rentals page.
    }


错误为:

第33行:</td>
第34行:< td>
第35行:@ Html.DisplayFor(modelItem => item.OnHire)
第36行:</td>
第37行:< td>
因此,我在这里尝试使用静态布尔值,这将允许我在其他类中使用它.

然后在电影课中,我想说的是rental.OnHire = true时,movie.onHire也将为true.

想法是,当用户租借副本时,他们在租借页面上将onHire更改为yes,这会将电影页面上的电影从false更改为true..


The error being:

Line 33: </td>
Line 34: <td>
Line 35: @Html.DisplayFor(modelItem => item.OnHire)
Line 36: </td>
Line 37: <td>
So here I was trying to use a static bool, which will allow me to use it in a different class.

Then in the movies class I was trying to say when the rental.OnHire = true, the movie.onHire will also be true.

The idea being when the user rents out a copy they change the onHire to yes on the rental page, which will change the movie on the movies page from false to true..

<pre lang="sql">
<pre lang="c#">

  public class Movie
    {
        public int MovieID { get; set; }

        public string Title { get; set; }

        public string Producer { get; set; }

        public string Genre { get; set; }

        public bool? OnHire { get; set; }

       // if (Rental.Onhire)
        //{
            //OnHire = true;
       // }

    }
}
&lt;/pre&gt;</pre>


虽然它不是捡布尔.有人可以告诉我我要去哪里错了.


Although it wasnt picking up the bool. Could someone please advise where I am going wrong. Am I going about this the right way?

推荐答案

我不会使用布尔型吗?如果您真的需要使用布尔?那么您需要考虑一个NULL
I wouldn''t use a Bool? if you really need to use a Bool? then you need to account for a NULL


这篇关于mvc在模型类中使用bool更改db中的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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