Reputation: 1187
In my ASP.NET MVC view I have the following hidden variables.
@Html.HiddenFor(m => m.TotalAmount)
@Html.HiddenFor(m => m.SelectedAmount)
Which I was able to display in the page using,
@Model.TotalAmount
I used AJAX to get these hidden fields as below.
$("#TotalAmount").val()
and $("#SelectedAmount").val()
.
TotalAmount is always 0 and I am getting SelectedAmount correctly.
Please help me to find what wrong with this.
Update:
From developers tool I see :
However I am getting the value of Model.TotalAmount printed in the page using @String.Format(new CultureInfo("en-US"), "{0:N}", @Model.TotalAmount)
Upvotes: 1
Views: 1170
Reputation: 489
Try this: this will help you for the same purpose
<input type="hidden" name="Step" value="@Model.TotalAmount" />
Upvotes: 1
Reputation: 4207
You can always just print the value to your script like so:
<script type="text/javascript">
function myFunction() {
var totalAmount = @Model.TotalAmount;
}
</script>
Ofcourse you still need the hidden fields if you want to keep the values in your model in submit.
This is just one solution to your problem.
Upvotes: 1