[RESOLVED]Designing models

Hi,

 I am quite new to the MVC and I have problem of correctly designing view model. My scenario is that I have a  main View Model which involves several selecting options  from several drop down list . for instance,

Main View model  ( lets say create a license ) is License, for that I need allocate a time slot from a drop down, data package etc..  and I also want to display display these information in detail view also.

I know I can achieve this by adding  ,

     public
Dictionary<int,
string>
DayOptions {
get;
set;
}

  public

int

SelectedDayOption {
get;
set;
}

 but when I display data, how to use the same model ?

Any guidance would be highly appreciated.

Thank you!

  

roshan605

hen I display data, how to use the same model ?

the Model is a class that contains 

roshan605

 public
Dictionary<int,
string>
DayOptions {
get;
set;
}

  public

int

SelectedDayOption {
get;
set;
}

as properties.

Try something like below,

@Html.DropDownListFor(model => model.SelectedDayOption, Model.DayOptions, null)

 

thank you,  I just want to display the string option as well. so is it a good practice to later property a object ?  example instead of

Public int
SelectedDayOption {
get;set;
}

create the property like this

public Day SelectedOption { get ;set;} where Day will have int and string

Hi roshan605,

Thanks for your post.

Do you want to create a property ,like this:

roshan605

public Day SelectedOption { get ;set;}

and you want this has int and string type?

if so,you need to create a class contains int and string type property,like this:

public class Day
    {
        public string yourpropertry1{ get; set; }
        
        public int yourproperty2{ get; set; }
    }

Hope this can be helpful.

Best Regards,

Eileen

Leave a Reply