'Set value from model in a label using html helper
I have given view model.I have to set the value of Amount(which is getting retrieved from table using linq) on a label using Html helper.
public class AllocationViewModel
{
public long ID { get; set; }
public string Name { get; set; }
public double Amount { get; set; }
}
Code for view page:--
@model Assetry.Controllers.AllocationViewModel
@using (Html.BeginForm("Index", "Deal", FormMethod.Post))
{
@Html.DisplayFor(model => model.Amount)
}
Solution 1:[1]
Something like this maybe?
@model AllocationViewModel
@Html.DisplayFor(model => model.Amount)
Solution 2:[2]
Try this,
@Html.Label(Model.Amount)
or IF you want value in model,
@Html.LabelFor(model => model.Amount)
Solution 3:[3]
I think in your case you don't need a display template, except you want to represent a double in a sophisticated manner using a template.
Try something like that (if you want to just display the amount):
<span>@Model.Amount</span>
To edit:
@Html.LabelFor(m => m.Amount)
@Html.TextBoxFor(m => m.Amount)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Henrik |
Solution 2 | |
Solution 3 | martinoss |