Change label on change DropDownListFor value

十年热恋 提交于 2019-12-12 06:36:30

问题


I use a DropDownListFor and a label text on my page.

<%=Html.DropDownListFor(x => x.MotiveClientType,
                        new SelectList(
                            Model.ClientMotives, "Id", "Label", Model.MotiveClientType),
                        new { id = "ddlMotiveClientType" }
)%>                       

How can I change my label when selecting value on my DropDownListFor?


回答1:


I'm not aware of any functionality native to ASP.NET MVC that will allow you to do this, but doing it with jQuery is a fairly trivial matter. Here's an example of hooking up an event handler to the change event of the dropdown & then setting the label text:

$("#DropDownID").change(function () {
    $("#LabelID").text("Your text here");
});

Just replace the IDs with the relevant values.



来源:https://stackoverflow.com/questions/11826336/change-label-on-change-dropdownlistfor-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!