Reputation: 20987
I have an MVC Form in which I would to display some non editable values.
<form asp-action="AuthorizeTransaction" method="post">
<div asp-validation-summary="All" class="text-danger"></div>
<div class="form-group">
<label asp-for="To"></label>
<input asp-for="To" class="form-control" />
<label asp-for="Amount"></label>
<input asp-for="Amount" class="form-control" />
<label asp-for="Currency"></label>
<input asp-for="Currency" class="form-control" />
<label asp-for="Description"></label>
<input asp-for="Description" class="form-control" />
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
I know I probably can make the inputs readonly, but I would like to know if there is a way to display form values without using a textbox and still have the values posted. I would like to do something like this:
<label asp-for="Amount"></label>
<display asp-for"Amount"></display>
<input type="hidden" asp-for="Amount" class="form-control" />
Upvotes: 0
Views: 1133
Reputation: 121
As per my understanding, you want to display some values as non editable. So either you can use property like readonly or you can use @Html.DisplayFor(m => m.Property) an html helper from mvc to make something read only. It will render as a label in the form
Upvotes: 1