我有点问题,我想问是否有可能,如果是的话。例如,您有一个用于租车预订的创建表单。
Car model containts information like:
brand,model,costPerHour, NumberOfSeats(how many seat 4,5,7,...)
在创建表单 - 下拉列表中:
<div class="editor-label">
@Html.LabelFor(model => model.CarId, "Car")
</div>
<div class="editor-field">
@Html.DropDownList("CarId", String.Empty)
@Html.ValidationMessageFor(model => model.CarId)
</div>
在下拉列表中会有一个滑块,其中包含将要旅行的人数。
<div class="editor-label">
@Html.LabelFor(model => model.PersonsInCar)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.PersonsInCar)
@Html.ValidationMessageFor(model => model.PersonsInCar)
</div>
有没有办法限制PersonsInCar的编辑器,具体取决于Car.NumberOfSeats(从1到所选汽车的座位数)? 谢谢你的帮助。
答案 0 :(得分:1)
$.ajax({
type: "GET", //GET or POST or PUT or DELETE verb
url: ajaxUrl, // Location of the service
data: "", //Data sent to server in your case CarID Selected
contentType: "", // content type sent to server
dataType: "json", //Expected data format from server
processdata: true, //True or False
success: function (json) {//On Successful service call
var result = json.name;
$("#dvAjax").html(result);
},
error: ServiceFailed // When Service call fails
});
你必须在控制器中编写一个方法,在json中返回Number of Seats,这个方法接收CarID参数