different between @Model and @model

前端 未结 2 875
名媛妹妹
名媛妹妹 2020-12-14 10:48

Basically I\'m doing a test caused by one of excpetion.

By using return View(list_a) in controller I passed a list into my view, On my View page, the co

相关标签:
2条回答
  • 2020-12-14 11:01

    One is used to declare the strong type that the model is, and the other is used to access the model itself.

    The following says that the strong type used for the model is UniBlue.Models.KYC.

    @model UniBlue.Models.KYC
    

    This basically declares the 'variable' Model as that type. It's akin to doing the following:

    UniBlue.Models.KYC Model;
    

    Model is a variable, @model is a keyword saying what type Model will be.

    Your error is because you've declared Model as KYC, but KYC is not enumerable. You're using it in a foreach expecting an IEnumerable<UniBlue.Models.KYC> which is not the case.

    If your model is truly a list, then use

    @model IEnumerable<UniBlue.Models.KYC>
    
    0 讨论(0)
  • 2020-12-14 11:15

    @model denotes the type of a variable you refer as @Model

    @model string
    
    @Model.ToUpper(); // works as @Model is of type string
    
    0 讨论(0)
提交回复
热议问题