我在我的MVC应用程序中使用kendo.ui.Slider,如下所示:
@(Html.Kendo().Slider()
.Name("slider") //The name of the slider is mandatory. It specifies the "id" attribute of the widget.
.Min(0) //Set min value of the slider
.Max(100000) //Set min value of the slider
.Value(50000) //Set the value of the slider
.SmallStep(1000)
.LargeStep(10000)
.HtmlAttributes(new { style = "width:700px;" })
.Tooltip(tooltip =>
{
tooltip.Format("{0:n0}");
})
.Events(e =>
{
e.Change("sliderOnChange");
})
)
<script>
function sliderOnChange(e) {
var slider = $("#slider").data("kendoSlider");
var sliderValue = slider.value();
alert(sliderValue);
}
</script>
如何在此处绑定模型值而不是分配静态值(.Value(50000))?
答案 0 :(得分:0)
<强>模型强>
如果您的模型如下:
public class AModel
{
public int? Percentage { get; set; }
}
以上允许在针对模型的操作中设置属性。
然后,您可以使用SliderFor
而不是Slider
查看强>
@(Html.Kendo().SliderFor(m => m.Percentage)
.Min(0) //Set min value of the slider
.Max(100000) //Set min value of the slider
.SmallStep(1000)
.LargeStep(10000)
.HtmlAttributes(new { style = "width:700px;" })
.Tooltip(tooltip =>
{
tooltip.Format("{0:n0}");
})
.Events(e =>
{
e.Change("sliderOnChange");
})
)
请注意上面已移除的Name
媒体资源和Value
设置者。
由于{View}模型中定义了Percentage
属性,它会自动呈现为Slider的Name
属性。
这允许模型绑定器拾取它并在模型对象中发布设置值。