c# - razor list<MyObject> element was not closed -
i have cshtml template , i'm using razor populate it. i'm passing object has several sub-lists inside , need values 1 of items in 1 sub-lists use in body of text. in opening tag have this:
@{ var myid = @model.myid; list<myobject> newobj = @model.mylist.where(l => l.id == myid).tolist(); }
but when try execute template, throws error '<'myobject'>' not closed, elements must have matching self-closing tag or end tag. understand seems reading html tag, why since inside programming markup? can not call list object in razor? if so, how specific sub-list of items?
i've checked rest of page , html has closing marks.
i think fix code have following:
@{ var myid = model.myid; list<myobject> newobj = model.mylist.where(l => l.id == myid).tolist(); }
which removes @ in front of model's.
however feel better solution problem try , keep logic code in controller rather view.
as example, if using partial view.
in view call action , pass in model this:
@html.action("myaction", model)
this call controller action select i.e.
[childactiononly] public actionresult myaction(mymodel model) { var newlist = model.mylist.where(l => l.id == myid).tolist(); return partialview("_mypartial", newlist); }
then use @model
attribute within partial i.e.
@model list<myobject>
Comments
Post a Comment