How to assign the value of a TempData ["Test"] or ViewBag.Id to an html input?

0

I would like to know how do I get the value of my tempData variable and put in an html input, in value maybe ... could anyone help me?

Code below:

<div class="container-fluid">
    <form method="post" style="margin: 0 auto; padding: 25px; background-color:white;">
        <input type="hidden" name="DataHora" id="DataVotacao" value="" readonly />
        <input type="text" name="IdFuncionario" id="DataVotacao" value="@(ViewBag.Funcionario)" readonly />
        <div>
            <label for="Senha">Recurso:</label>
            @Html.DropDownList("IdRecurso", (IEnumerable<SelectListItem>)ViewBag.Recurso)
        </div>
        <div>
            <label for="Comentario">Comentário(obrigatório):</label>
            <textarea name="Comentario" required="required"></textarea>
        </div>
        <div>
            <button type="submit" name="ConfirmaPassword" class="btn-primary btn-block" style="position:center">Cadastrar</button>
        </div>
    </form>
</div>
    
asked by anonymous 16.11.2017 / 00:03

1 answer

0

In your controller and method use ViewData , example:

public IActionResult Index()
{
    ViewData["IdFuncionario"] = 1;
    return View();
}

and in the View concerned:

<input type="text" value="@(ViewData["IdFuncionario"])" name="IdFuncionario" />

is a way to pass information from controller to its View , but, not recommended, the correct thing is to work with ViewModel .

Examples

In this link explains the difference between ViewBag, ViewData, and TempData , in this link and how another link

    
16.11.2017 / 00:41