user3439890
user3439890

Reputation: 21

MVC Acces data in view without using a @Foreach (var item in model)

I am trying to only create one "create new" where it queries the type of the product with it. But i dont know how to access without the @foreach.

@foreach(var item in Model)
{
    @Html.ActionLink("Create New Entity", "CreateEntityType", new { EntityTypeEnum = item.EntityTypeEnum})
}
</p>

Upvotes: 0

Views: 677

Answers (1)

If your Model is an array and you simply wish to access the first index [0] for EntityTypeEnum (or any index) you can do the following.

 @Html.ActionLink("Create New Entity", "CreateEntityType", new { EntityTypeEnum = Model[0].item.EntityTypeEnum})

Upvotes: 1

Related Questions