在模型类MVC上更改bool [英] change bool on a model class MVC

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

问题描述

嘿伙计......所以我使用mvc3为租赁系统创建一个数据库网站。

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

在我的租赁中我的模型文件夹中的.cs就像... ...

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

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;

//另一方面,我必须在public statick bool中取出'static'吗? onhire

//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. }

错误是:

Line 33:         </td>
Line 34:         <td>
Line 35:             @Html.DisplayFor(modelItem => item.OnHire)
Line 36:         </td>
Line 37:         <td>

所以这里我试图使用静态bool,这将允许我在不同的类中使用它。

So here I was trying to use a static bool, which will allow me to use it in a different class.

然后在电影课上,我试图说出租时.OnHire = true,movie.onHire也是如此。

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

这个想法是当用户出租副本时,他们会将出租页面上的onHire更改为是,这会将电影页面上的电影从'假'更改为'真''为'Onhire'

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' for 'Onhire'

    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;
       // }

    }
}




虽然它没有拿起布尔。有人可以告诉我哪里出错了。我是否正确行事?

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




推荐答案

嗨。

你需要在租借电影时更改它。

you need to change it when you rent the movie.

当你保存租金时,你需要在控制器上进行更改与电影相同。

On your controller when you save the rent, you have to do the same to movie.


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

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