Home > other >  Unable to read value from document
Unable to read value from document

Time:07-14

I'm a novice in MVC, Below is my code I am unable to read the value of an ID and use that in an decision statement, I am getting "The name "Text" does not exist in current context", I need to work on the if statement based on the value I get from my document.getElementById

    @{

        var grid = new WebGrid(Model.Abc, canPage: true, canSort: true, rowsPerPage: 50);
    }


    @{
        var gridColumnsNew = new List<WebGridColumn>();
        gridColumnsNew.Add(grid.Column("Details", header: "Id"));
       
        <text>
            var obj = document.getElementById("NextAction").value;
        </text>

        if (@text.obj == "Start")
        {
            gridColumnsNew.Add(grid.Column("Temp"));

        }
        
}

CodePudding user response:

Try using

document.getElementsByName("NextAction").value;

I have seen in my case that Blazor changes Id to name. Note: I am using DevexpressBlazor

CodePudding user response:

Did you checked if you are able to see on the html generated that ID?

If yes, Did you have any JS error before?

Looks like the ID not was generated or the place where you are run the getElementById don't have visibility to your specific code.

  • Related