在@ Html.DropDownListFor使用选定的值 [英] Using selected value in @Html.DropDownListFor
问题描述
您好我要建应用程序中显示的报道,我有一组设置的,我想用户选择,而他选择preVIEW更新。它是强类型的视图:
Hi I'm building application to display reports, I have a set of setting which I would like the user to select, and while he selecting a preview updates. It is strongly typed view:
@model MRS.UI.Models.SettingsModel
@using (Html.BeginForm("Settings", "Report", FormMethod.Post))
{
<div class="white-box edit-box">
@Html.DropDownListFor(m => m.range, new SelectList(new List<Object>{new { value = 0, text = "12 hours"},
new { value = 1, text = "24 hours"},
new { value = 2, text = "4 days"},
new { value = 3, text = "8 days"},
new { value = 4, text = "16 days"},
new { value = 5, text = "month"},
new { value = 6, text = "quarter"},
new { value = 7, text = "year"}
},
"value",
"text",
Model.range
), new { @class = "select_change" }
)
@Html.TextBoxFor(m => m.title)
@Html.RadioButtonFor(m => m.layout, 1) <p>Layout 1</p><br />
@Html.RadioButtonFor(m => m.layout, 2) <p>Layout 2</p><br />
@Html.RadioButtonFor(m => m.layout, 3) <p>Layout 3</p><br />
@Html.RadioButtonFor(m => m.layout, 4) <p>Layout 4</p><br />
<input class="blueButton" type="submit" value="Complete Report"/>
</div>
}
<script>
$('.select_change').change(function () { alert(@Model.range); })
</script>
在我preSS完整的报告的数据被保存,然后我可以用它在不同的看法,但我怎么可以把它用在了同样的看法,而被选中。我试图使用JavaScript的警告消息的形式显示的范围值,但它显示未更新的价值。
After I press "Complete Report" data is saving and then I can use it on different view, but how can I use it on the same view, while is selected. I tried to use JavaScript to display value of range in a form of alert message, but it displays not updated value.
我怎么能在@ Html.DropDownListFor?
How can I use selected value in @Html.DropDownListFor ?
非常感谢您的帮助。
推荐答案
您不能使用从模型,这是不更新客户端(和变更$ C未来的价值$ C>事件发生在客户端)
you can't use the value coming from your Model, which is not updated on client side (and the change
event happens on client)
您需要做的
$(.select_change).change(function() {
alert($(this).val());//selected value
alert($(this).find('option:selected').text());//selected option text
});
这篇关于在@ Html.DropDownListFor使用选定的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!