Last post Feb 18, 2018 06:52 PM by bruce (sqlwork.com)
Feb 18, 2018 04:04 PM|rogersbr|LINK
I have a details page in MVC with about 1000 <dt><dd> table entries. So many that I want to 'hide' the ones that don't have data in them. It appears impossible with the <dl> <dt> <dd> </dl> setup because even if I add <dd id="myvalue1"> sdfascy3423 </dd>
and try to use the reference
var someval1 = document.getElementById("myvalue1");
if I try to extract the value with
var somedata1 = someval1.value;
Nothing happens, except we see in F12 that it failed, someval1.value is undefined. Cannot get the data value from the dt/dd no matter what. Tried using reference.innerhtml or? undefined.
I dont want to have to go into each of the 1000 <dd>'s and add a unique ID, the goal is just to see if the value of the model data is null or not. So now it becomes how to reference the model data in the page and do this test?
For other pages I built a foreach loop using keyword SOME, which worked great to find nulls, made an array of the model value names and passed them in using SOME to the function, returning whether that array was all null or if at least one model was found
Assumed this would work in the DETAILS page, but it does not. Found I cant even get data to test. Another possible way would be to try
var model = @Html.Raw(Json.Encode(Model));
And then use some kind of code to iterate each group, just cant seem to read any data out
Feb 18, 2018 06:52 PM|bruce (sqlwork.com)|LINK
only form elements (input, select, textarea) have a value property. all other dom elements have child nodes. you can convert the child nodes to a string via the innerHTML, innerText or textContent properties. only form elements are included post back.
is perfectly valid (though I'd use newtonsoft rather than the webhelpers), and probably a better approach if you need to know null vs blank. you need to know if camel case is set to know if the propertyNames start with upper or lower case. all collections
a simple view source will give you all the answers. but