初心者の質問には申し訳ありませんが、なぜvarの値をC#プロパティに設定できないのですか? 私はいくつかのモデルプロパティ&計算を行う取得した値を使用する方法を見つけようとしています....MVCビューでC#プロパティを使用しているときに変数が設定されていません
@using System.Collections
@using System.Runtime.Serialization
@using CarRentalMVCApp.Models
@model CarRentalMVCApp.Models.Rentals
@functions {
public string selection { get; set; }
public decimal Price { get; set; }
}
@{
ViewBag.Title = "Create";
}
<script>
function select() {
var $el = $("#selectedCar");
var selected = $("#selectedCar option:selected").text();
$el.on("change", @selection = selected);
alert(@selection);
}
function Rental() {
var choice = select();
@foreach (var car in ViewData["availableCars"] as IEnumerable<Vehicles>)
{
if (selection != null && int.Parse(selection) == car.מספר_רכב)
{
Price = car.עלות_ליום_השכרה;
}
}
if (firstDay != null && lastDay != null) {
var rentalData = {
price: @Price,
firstDay: $("#beginRental").val(),
lastDay: $("#endRental").val()
}
alert(rentalData);
}
}
</script>
@selectionは常に0と私はそうのような別のveriableでそれを設定しようとするものに等しいです。 :
@selection = selected;
0のままです。あなたは助けるために時間やリンクを持っている場合、私は、説明をappresiateう@記号が含まれている場合にはjavascriptの変数のいずれかのタイプを使用することはできませんなぜ私はまた、カントが理解
.....
を返しますか? js変数から値を設定していますか? – Shyju
はい...しようとしています... $ el.on( "change"、@selection = selected); –