我有兩個文本框。一個文本框用於輸入,另一個用於輸出。當通過按鈕點擊在第一個文本框中輸入數字時,我想通過單擊方形按鈕在第二個文本框中找到該數字的平方。但我無法獲得理想的結果。單擊方形按鈕時,第二個文本框中不會顯示任何內容。 下面是代碼片段:如何計算數字的平方?
@Html.TextBoxFor(model => model.textBox, new { @readonly = "readonly" })
<br/>
@Html.TextBoxFor(model => model.textBox1, new { @readonly = "readonly" })
<input name="button" type="submit" id="btntwo" value="2" />
<input name="button" type="submit" id="btnthree" value="3" />
<input name="button" type="submit" id="btnfour" value="4" />
<input name="button" type="submit" id="btnSqr" value="Sqr" />
這裏是控制器代碼片段:
if (button == "Sqr")
{
model.value1 = model.textBox;
model.textBox1 = (float.Parse(model.value1) * float.Parse(model.value1)).ToString();
}
注:我只提供這是解決問題所需的代碼。
您的標題有點令人誤解,您的第二個片段顯示您知道如何計算數字的平方。設置斷點是否顯示正確的值? – Sayse
請修復此問題的標題。你顯然知道如何計算一個數字的平方,你遇到的問題是顯示一個數字。 –
您是否返回模型以再次查看? –