2 Replies - 11319 Views - Last Post: 12 December 2012 - 06:19 PM

#1 Xna4life   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 78
  • Joined: 21-February 12

mvc using bool in model class to change property

Posted 22 October 2012 - 04:53 PM

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


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' 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?

Is This A Good Question/Topic? 0
  • +

Replies To: mvc using bool in model class to change property

#2 BattlFrog   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 73
  • Joined: 09-April 12

Re: mvc using bool in model class to change property

Posted 12 December 2012 - 11:35 AM

You mention an error, what was the error? What is not working?
Was This Post Helpful? 0
  • +
  • -

#3 Nakor   User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: mvc using bool in model class to change property

Posted 12 December 2012 - 06:19 PM

I'm not sure why what you're trying to do would require a static OnHire property. Is OnHire supposed to apply to every Rental object? Say if you changed the OnHire to false on one item then it should be false on every item? Static basically means there's only a single instance of that property/method for the class, regardless of how many instances of that class there might be.

So you have an OnHire property in the Rental class and it sounds like you also have an OnHire property in the Movie class? Do you really need it in both classes or can you just access the OnHire in the Movie class from the Rental class based on the movie ID?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1