C
C
CallMeYourDaddy2020-09-09 13:38:55
C++ / C#
CallMeYourDaddy, 2020-09-09 13:38:55

How to iterate over a collection and assign values ​​to a variable?

I need to make a web shell. I did almost everything, only the following remains: Remember the history of entered commands in the database on the server, restore the history of those entered when entering the page, scroll through the history with the up and down keys (as, for example, in bash or PowerShell).
I have a database where the commands that I entered in the field are already added, but I can't implement viewing commands using the keys.

I have html code:

<div class="input-group mb-3">
        <input type="text" class="form-control" placeholder="Bash command" aria-label="Bash command"
               aria-describedby="basic-addon2" <b>@bind="_bashCommand"</b> <b>@onkeydown="OnKeyDown"</b>>
        <div class="input-group-append">
            <button class="btn btn-outline-secondary" @onclick="Method" type="button">Send</button>
        </div>
    </div>


This is how I get all the commands that are in the database:
private IEnumerable<BashData> _allCommands = new List<BashData>();
private void GetAllBashCommands()
{
     _allCommands = repository.GetAllCommands();
}


And here is the button click handling method:
private void OnKeyDown(KeyboardEventArgs args)
    {
        switch (args.Key)
        {
            case "ArrowUp":
                _bashCommand = ;
                break;
            case "ArrowDown":
                _bashCommand = ;
                break;
        }
    }


That is, I click on the button and _bashCommand is assigned an element of the _allCommands collection.
How to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
cicatrix, 2020-09-09
@cicatrix

On the client side, after pressing the keys, you need to initiate an Ajax request to the server, then catch the response from the server, which command to put in the field.
But every time it's kind of crooked to follow the commands to the server. I would pass the last 10 commands along with the page, and climb the server only if I need to get into an earlier history.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question