I'm trying to print out all of my model values into my view.
I don't wish to "hard-code" it for each value, but rather have it dynamically grow accordingly to my models structure. This is so that non-developers can test out if everything gets inserted correctly into the database, what values are added etc
Currently I have this code in my controller that prints out all the variables in my model, but I'm not sure how to connect some certain objects values onto it
var result = "";
var myAssembly = typeof(Person).GetTypeInfo().Assembly;
var properties = Converters.GetTypesInNamespace(myAssembly, "Domain.Models")
.FirstOrDefault(a => a.Name == "Person")
.GetProperties().ToList();
for (var i = 0; i < properties.Count; i++)
{
result += properties[i].Name + Environment.NewLine;
}
return Ok(result);
And this is the custom method I use
public static Type[] GetTypesInNamespace(Assembly assembly, string nameSpace)
{
return assembly.GetTypes()
.Where(t => String.Equals(t.Namespace, nameSpace, StringComparison.Ordinal))
.ToArray();
}
I'd like to get back a view that displays all the values for a Person with a certain id, ie Person/5 returns it's FirstName and LastName, but if I now add a new variable to my model - the view will display that as well
Dictionary<string, string>as property on your ViewModel and loop through it in the view?