ASP.net
Awesome
Learn
Forum
Buy
Demos
Sign In
☾
☀
Switch to
Dark
Light
Mode
this site works best with javascript enabled
Ask Question
Can I add custom attr for AjaxDropdownFor ?
Title:
B
I
{code}
?
I want to add my attribute in option tag of generate from AjaxDropdownFor like below : <select> <option myattr="1" value="1">aaa</option> <option myattr="0" value="3">bbb/option> </select> I have one textbox when user change Dropdown to - item has myattr="1" then textbox enabled - item has myattr="0" then textbox disabled Can I do ?
Save Changes
Cancel
nutfergie
asked at 30 Mar 2018
Answers
B
I
{code}
?
think it would be easier if you inherit `KeyContent` and add another property: public class MyKeyContent : KeyContent { public MyKeyContent(object key, string content, int myattr) : base(key, content) { MyAttr = myattr; } public int MyAttr { get; set; } } after in the controller you will return `MyKeyContent` instead of `KeyContent`, and on the client side in the `change` event handler you can look in the last result returned and check for MyAttr: $('#dropdown').change(function(){ var val = $(this).val(); var lrs = $(this).data('o').lrs; for(var i = 0; i < lrs.length; i++){ if(lrs[i].k == val){ alert('my attr for current val is ' + lrs[i].MyAttr); } } });
Save Changes
Cancel
Omu
answered at 30 Mar 2018
please
Sign In
to leave an answer
By accessing this site, you agree to store cookies on your device and disclose information in accordance with our
cookie policy
and
privacy policy
.
OK