c# - Html DropDownListFor issue -


i have problem dropdownlistfor, want dropdownlist 1,2,3,4,5 etc. on view.

in model class:

public class pagemodel  {    [displayname("quantity")]    public int quantity { get; set; } } 

i have created quantity class

 public class quantity     {         public int selection { get; set; }     } 

a htmllist class

public static class htmllists     {        public static ienumerable<quantity> selections = new list<quantity> {              new quantity {                 selection = 1             },             new quantity {                 selection = 2             }         }; 

on view:

@html.labelfor(m => m.quantity):         <td>@html.dropdownlistfor(m => m.quantity, new selectlist(htmllist.selections, "selection")) 

it giving me error @ htmllist.selections:

the name 'htmllist' not exists in current context

edit:

my error issue fixed @using yournamespaceofstaticclass

but have folliwing problem:

instead of showing me selection 1 , 2 in dropdownlist showing me:

modelnamespace.quantity modelnamespace.quantity

i think beacause list empty..

namespace of quantity class:

namespace modelnamespace { 

you need include namespace static class in view.

@using randomproject.helpers; 

and 1 suggestion, instead of creating static class, can create property in viewmodel.

public class yourviewmodel {       public ienumerable<quantity> selections {get;set;} } 

Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -