Click here to Skip to main content
15,563,054 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an array using MVC Model, which returns values of example data
var result = [{"Id":399,"Number":"Test09_05_2022","Name":"Test_10_03_2022","Status":"Inactive"},
              {"Id":377,"Number":"000-1","Name":"New", "Status":"Inactive"},
			  {"Id":386,"Number":"000-8","Name":"NewEmployee", "Status":"Active"},
			  {"Id":382,"Number":"05 FEB 2020,"Name":"Test","Status":"Active"}]


I am trying to find all Inactive Status and a hide a add Button.

What I have tried:

var result = @Html.Raw(Json.Encode(Model));
           
	        result.forEach(function (e) {
	          
	            var conStatus = e.Status;
         
                if (conStatus === "Inactive") {
	                $("#AddButton").hide();
	                return true;                         
                }
               else (conStatus === "Active")
               { 
                   $("#AddButton").show();
	                return true;              
                 }
 
	            return true;
	        });


This code is looping and defaulting to the first item and therefore hiding the Button even if it is Active. Any help will be appreciated.
Posted
Comments
Member 15627495 18-Oct-22 0:13am    
console.log(conStatus); will write in console the values involved;
it's "tracing" your vars
Richard Deeming 18-Oct-22 4:34am    
You haven't shown any of the HTML you're trying to modify. Based on your code, it looks like you've given the same ID to multiple elements, which won't work; IDs in a document need to be unique. When you try to modify the element with the ID AddButton, there is nothing to indicate which of those elements you're modifying, so you typically end up modifying the first one in the document.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900