ASP.NET MVC using same view to edit and create -
i've created view editing model. view strongly-typed , @ 1 point following:
@for (int = 0; < model.risks.count; i++) { @html.editorfor(m => model.risks[i])) }
now, working fine if collection not null, i.e if edit existing entity.
however i'd utilize same view creating new entity. crashes since collection null. how can create sure renders editor ?
one way have defaults when model new.
public ilist<risk> risks { { homecoming isnew() ? defaultrisks() : risks; } set { risks = value; } }
having property isnew can used in view illustration button text "create" or "save"
if end many if statements in view best seperate them.
that beingness said having same presentation model not bad thing.
asp.net-mvc-4 edit
No comments:
Post a Comment