我想尝试为我的 MVC 表单中的输入隐藏字段分配一个变量值。我以为我可以这样做,但变量的值没有被放入隐藏字段。任何想法为什么这是错误的方式?
注意:变量声明之间有一些代码......我只是想让事情变得简单易读。困扰我的特定代码行是:@value = @secondNumber
@{
ViewBag.Title = "Jakub Holovsky - Contact";
Random randomNumber = new Random();
int firstNumber = randomNumber.Next(0, 11);
int secondNumber = randomNumber.Next(0, 11);
int sumNumber = firstNumber + secondNumber;
}
<div class="divLeftSide">
<span>How much is @firstNumber + @secondNumber:</span>
@Html.TextBoxFor(m => m.FirstNumber, new { @type = "number", @id = "firstNumber", @class = "HiddenField", @value = @firstNumber })
@Html.TextBoxFor(m => m.SecondNumber, new { @type = "number", @id = "secondNumber", @class = "HiddenField", @value = @secondNumber })
</div>