asp.net mvc - Set value for joined table in MVC Razor -
i'm trying create razor page windows auth mvc app tracks created record. basic idea looks this:
public class user { public int id {get;set;} public string networkid {get;set;} } public class event { public int id {get;set;} public int userid {get;set;} public datetime created {get;set;} public virtual user user {get;set;} }
on razor page, i'm trying create hiddenfor
set user id , can't post correctly. setting created
field works correctly (@html.hiddenfor(model => model.created, new { value = datetime.now })
), userid
won't set.
this doesn't work:
@html.hiddenfor(model => model.user.networkid, new { value = user.identity.name })
this throws null reference exception:
@{ model.user.networkid = user.identity.name; } @html.hiddenfor(model => model.user.networkid)
there has easier way this, other looking networkid on table , pulling actual primary key.
any ideas?
Comments
Post a Comment