メソッドを使用してfunction
、ユーザーの入力により、データベースでアイテムの価格を自動的に取得したいと考えています。textbox("@Html.TextBox("ItemID")")
handle
//SalesSub.cs
public class SalesSub
{
public string ItemID { get; set; }
public int Qty { get; set; }
public decimal UnitPrice { get; set; }
}
//Create.cshtml
<script type="text/javascript">
function handle(e) {
//Detect when the user press 'Enter' Or 'Tab' Key
var keyCode = e.keyCode || e.which;
if (keyCode === 13 || keyCode == 9) {
var itemID = $('#ItemID').val()
//Get the item ID in the textbox value,
//so how to search the price of the
//item in database? Using SQL or Others?
$('#UnitPrice').val() = //Result After Search
}
return false;
}
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
</script>
<label>Item ID :</label>
**@Html.TextBox("ItemID", string.Empty, new { onkeydown = "handle(event)" })**
<label>Qty :</label>
@Html.TextBox("Qty")
<label>Sales Price :</label>
@Html.TextBox("UnitPrice")
}