Click here to Skip to main content
15,896,278 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: model vs Model Pin
Member 1206160020-Sep-15 0:18
Member 1206160020-Sep-15 0:18 
AnswerRe: model vs Model Pin
Kornfeld Eliyahu Peter20-Sep-15 0:56
professionalKornfeld Eliyahu Peter20-Sep-15 0:56 
GeneralRe: model vs Model Pin
Member 1206160020-Sep-15 1:34
Member 1206160020-Sep-15 1:34 
GeneralRe: model vs Model Pin
Kornfeld Eliyahu Peter20-Sep-15 1:57
professionalKornfeld Eliyahu Peter20-Sep-15 1:57 
GeneralRe: model vs Model Pin
Member 1206160020-Sep-15 2:57
Member 1206160020-Sep-15 2:57 
AnswerRe: model vs Model Pin
Kornfeld Eliyahu Peter20-Sep-15 3:11
professionalKornfeld Eliyahu Peter20-Sep-15 3:11 
GeneralRe: model vs Model Pin
Member 1206160020-Sep-15 3:41
Member 1206160020-Sep-15 3:41 
AnswerRe: model vs Model Pin
F-ES Sitecore20-Sep-15 1:12
professionalF-ES Sitecore20-Sep-15 1:12 
When referring to the model passed to the view you use Model. Your DisplayFor is an extension that works on the current model object and it uses a lambda expression to say what property you are interested in, with the "model => model.Name" being the expression. The way expressions work is you pick a variable that is used to refer to the object, that's the bit before the =>. Anything after the => you can use that variable. The variable can be anything though, the reason model.Name is working for you is because you called the variable model. This code is just as valid

C#
@Html.DisplayNameFor(xyz => xyz.Rating)


In that case xyz is the same type as your model and Rating is the property on your model.

Your code isn't valid though as your model is an IEnumerable which doesn't have properties like name etc. If you want to get the header row for your data, you can do something like

@Html.DisplayNameFor(model => model.First().Name)


"model" is your IEnumerable so you're accessing the Name property of the first item in your IEnumerable which will be a RestaurantReview type. Note this will fail if you don't have any items in your model, so check the model isn't empty first.
GeneralRe: model vs Model Pin
Member 1206160020-Sep-15 1:38
Member 1206160020-Sep-15 1:38 
GeneralRe: model vs Model Pin
Richard Deeming21-Sep-15 2:24
mveRichard Deeming21-Sep-15 2:24 
GeneralRe: model vs Model Pin
Member 1206160021-Sep-15 2:50
Member 1206160021-Sep-15 2:50 
GeneralRe: model vs Model Pin
Member 1206160021-Sep-15 2:56
Member 1206160021-Sep-15 2:56 
GeneralRe: model vs Model Pin
Richard Deeming21-Sep-15 3:19
mveRichard Deeming21-Sep-15 3:19 
GeneralRe: model vs Model Pin
Member 1206160021-Sep-15 4:31
Member 1206160021-Sep-15 4:31 
GeneralRe: model vs Model Pin
Richard Deeming21-Sep-15 6:14
mveRichard Deeming21-Sep-15 6:14 
GeneralRe: model vs Model Pin
Member 1206160021-Sep-15 8:41
Member 1206160021-Sep-15 8:41 
QuestionVSflexgrid control in asp.net mvc Pin
Shaikh Ansar15-Sep-15 19:06
Shaikh Ansar15-Sep-15 19:06 
AnswerRe: VSflexgrid control in asp.net mvc Pin
jkirkerx16-Sep-15 11:05
professionaljkirkerx16-Sep-15 11:05 
GeneralRe: VSflexgrid control in asp.net mvc Pin
Shaikh Ansar16-Sep-15 20:01
Shaikh Ansar16-Sep-15 20:01 
GeneralRe: VSflexgrid control in asp.net mvc Pin
jkirkerx17-Sep-15 6:23
professionaljkirkerx17-Sep-15 6:23 
GeneralRe: VSflexgrid control in asp.net mvc Pin
Shaikh Ansar17-Sep-15 18:03
Shaikh Ansar17-Sep-15 18:03 
QuestionAsp.net session Pin
Member 1198569615-Sep-15 2:37
Member 1198569615-Sep-15 2:37 
AnswerRe: Asp.net session Pin
jkirkerx16-Sep-15 11:02
professionaljkirkerx16-Sep-15 11:02 
QuestionASP.NET Pin
scud1014-Sep-15 23:35
scud1014-Sep-15 23:35 
AnswerRe: ASP.NET Pin
Richard MacCutchan14-Sep-15 23:53
mveRichard MacCutchan14-Sep-15 23:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.