私の ASP.NET MVC4 アプリケーションでは、strongled 型を持つかみそりビューがあります。それは非常に単純です..ここでの主なことは、このクラスにIsCorrect()
メソッドがあることです。
public class AbsoluteArithmetic
{
public decimal? Result { get;set; }
....
public override bool IsCorrect
{
get { return ... }
}
}
以下を見てください。Result というプロパティを含む textBox があります。また、行を開始する最初のコードも参照してください。最初@if (@Model.IsCorrect()) {
に、このメソッドを使用して画像を更新します。
そのため、テキストボックスがフォーカスを失ったときに、もう一度更新するか、トリガーを起動して画像を更新したいと思います。AJAX と JQuery を使用する必要があると思いましたが、何をすべきかわかりません。
@model Contoso.MvcApplication.Models.Exercises.AbsoluteArithmetic
<div>
@using(Html.BeginForm())
{
@***** when the textbox loses the focus, update the following code*****@
@if (@Model.IsCorrect()) {
<img src="correct.png" />
}
else {
<img src="error.png" />
}
@**********************************************************************@
<span style="padding:3px; font-size:18px;">@Model.Number1</span>
<span style="padding:5px; font-size:18px;">+</span>
<span style="padding:5px; font-size:18px;">@Model.Number2</span>
<span style="padding:5px; font-size:18px;">=</span>
<span style="font-size:18px">@Html.TextBoxFor(model => model.Result, new { style = "width:60px; font-size:18px;" })</span>
}
</div>