c# - Should i instantiate a new model? -
mvc. passing data view in model. in repository map linq result model. in controller send data. 1 should do:
list<personmodel> people = new list<personmodel>(); people = repo.getpersonlist(); return view(people);
or
list<personmodel> people = repo.getpersonlist(); return view(people);
as mentioned, in repo map result model, new model instance:
var query = p in _db.person orderby f.lastname select new personmodel { id = f.personid, lastname = f.lastname }; return query.tolist();
either 1 works. use second 1 because thinking, repo creating new model passing controller when call repo.getpersonlist function. should create new instance in controller well, or continue am?
go second.
your first snippet has redundant new list<t>
call allocates new list, while next line overrides reference newly created list repo
. absolutely no need that.
Comments
Post a Comment