I have a viewModel in Asp.net mvc5 that contains a object:
public class ConvenioViewModel
{
public Convenio Convenio { get; set; }
public string AnotherProperty {get;set;}
}
and I need that this property be populate with a json in Form Submit, because I populate this in input hidden with Json:
@Html.HiddenFor(x => x.Convenio, new { @id = "convenioJson" })
and my Javascript is this:
$('#convenioJson').val(JSON.stringify(data.List[i]));
My Json is this:
"{'Descricao':'UNIMED ','Id':1,'CodigoLogin':'bortolop','DataStamp':'/Date(903621226000)/'}"
but when I submit this form, my property "Convenio " is null. what is the way to populate this in form submit? in ajax I already know
Conveniois a complex object. You cannot bind a complex object to an input (look at the html your generating). You need an input for each property of the model. BUt what is the point of this - they can't be edited, so if you need the object in the POST method, then just get it again