I have a View
, where the user must fill some fields, and have a last field that I left it disable
, and I would like this field to appear the user name, however how do I fill in?
Model
:
public class CombustivelModels
{
[Key]
public int CombustivelId { get; set; }
[Required]
public decimal km_inicial { get; set; }
[Required]
public decimal km_final { get; set; }
[Required]
public decimal litros { get; set; }
[Required]
[DataType(DataType.Currency)]
public decimal valor { get; set; }
[Required]
public string UserId { get; set; }
}
View
:
<div class="form-group">
@Html.LabelFor(model => model.UserId, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => User.Identity.Name, new { htmlAttributes = new { @class = "form-control", @disabled=""} })
@Html.ValidationMessageFor(model => model.UserId, "", new { @class = "text-danger" })
</div>
</div>
Example:
Butwhentryingtosave: