c# - How to Convert an IEnumerable model object to single model object in view , MVC3 -
this not duplicate.though other question same got solved when deviated procedure. here again stumbled upon same question.
iam using db first approach. have context file called dynaportal.context.cs, has class called dynaportalentities:-
public partial class dynaportalentities : dbcontext { ... public dbset<page> pages{ get; set; } public dbset<templatemaster> templatemasters { get; set; } }
in view
@model dynaportalmvc.models.dynaportalentities
and in foreach loop
@foreach (var item in model.templatemasters) {}
in same view , need page model not ienumerable, this:-
@html.editorfor(model => model.pages.title)===========>this shows error under title
so here should convert ienumerable model.pages single page object model.pages.title.
yes, if understand correctly, razor not know page
want title since asking title
of pages
.
usually, loop through pages
, output each title using @foreach
. or, index pages
: @html.editorfor(model => model.pages.first().title)
.
Comments
Post a Comment