asp.net mvc - different between @Model and @model -


basically i'm doing test caused 1 of excpetion.

by using return view(list_a) in controller passed list view, on view page, code like:

@{     viewbag.title = "kyc_home"; } @using uniblue.models; @model uniblue.models.kyc ... @foreach(kyc in model) ... 

there exception says:

cs1579: foreach statement cannot operate on variables of type 'uniblue.models.kyc' because 'uniblue.models.kyc' not contain public definition 'getenumerator' 

but, when changed code @model page looks on title shows:

system.collections.generic.list`1[uniblue.models.kyc] uniblue.models.kyc 

as regular html text

can tell me why happened? should remove strange title line?

one used declare strong type model is, , other used access model itself.

the following says strong type used model uniblue.models.kyc.

@model uniblue.models.kyc 

this declares 'variable' model type. it's akin doing following:

uniblue.models.kyc model; 

model variable, @model keyword saying type model be.

your error because you've declared model kyc, kyc not enumerable. you're using in foreach expecting ienumerable<uniblue.models.kyc> not case.

if model list, use

@model ienumerable<uniblue.models.kyc> 

Comments