c# - Passing more multiple queries in a View ASP.NET -


in repository class have 2 queries want appear in 1 view:

public classxxxx getxxxolist(string name) {     return context.classxxxx.where(v => v.name == name).single(); } 

and second query in repository class have:

public ienumerable<classxxxx> list() {     return context.classxxxx.tolist(); } 

then in view doing this:

@model ienumerable<namespace.models.classxxxx>  @model namespace.models.classxxxx 

to return 2 queries in view respectively. asp.net throws exception on using @model twice in 1 view.

instead of:

@model ienumerable<namespace.models.classxxxx> @model namespace.models.classxxxx 

you can create viewmodel class, contains needed data:

public class yourcontextviewmodel {     public list<person> person { get; set; }     public string username{get;set;}     ... } 

it's idea create viewmodel object populate views.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

android - CollapsingToolbarLayout: position the ExpandedText programmatically -

Listeners to visualise results of load test in JMeter -