Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.getJason and dynamically created options in partial view MVC3 #733

Closed
allen-628 opened this issue Jul 22, 2012 · 7 comments
Closed

.getJason and dynamically created options in partial view MVC3 #733

allen-628 opened this issue Jul 22, 2012 · 7 comments

Comments

@allen-628
Copy link

I am trying to dynamically create options items for a chosen in a partial view using MVC3. The items are called from the controller through .getJason(). The function is returning a series of options (in this country names and ids). I then use .html(items) to supply chosen with these options. I tried to use $('CountrySelect').chosen() as suggested in issue 363; however, the select element falls back to an html select element rather than the chosen eleement. Any suggestions as to how to retain the chosen element?

I am using JQuery 1.7.2

The list is returned through:
$.getJSON("controller/action", function (data) {
var items;
$.each(data, function (i, country) {
items += "" + country.Text + "";
});
$('.chzn-select').html(items); // 247 country elements retrieved here
});
And then I call--
$("CountrySelect').chosen();
Which results in an HTML select element.
If I use
$('.chzn-select').chosen();
then the chosen element is displayed but the options are empty.
Help would be greatly appreciated.
TIA Allen

@koenpunt
Copy link
Collaborator

Is the <select> showing the options when chosen hasn't been applied?

@allen-628
Copy link
Author

I am using Razor syntax and the following statement which does display the options in a select tag:
@Html.DropDownFor(ddl=>ddl.CountryId, new SelectList(Model.Countries, "Id", "Name",'Select your country")
Please note at this line $('.chzn-select').html(items); // 247 country elements retrieved here; there are 247 well formed option tags in var items with the correct value (countryId) and countryName between the opening and closing tag.
e.g.

<option value=1>Canada</option>
<option value=2>United States of America<\option>
... remaining 243 countries

@koenpunt
Copy link
Collaborator

Please read what you just wrote and see if you can understand..
So please add some interpunction and make use of markdown for styling your code snippets. Then I'll try again.

@allen-628
Copy link
Author

This is probably going to sound stupid How do I add interpunction and mark down? I am not familiar with this markup-markdown

@koenpunt
Copy link
Collaborator

There is a link on the right top of the input field: http://github.github.com/github-flavored-markdown/

@allen-628
Copy link
Author

I added the markdown to your question about the select tag. Please review that reply

@pfiller
Copy link
Contributor

pfiller commented Apr 24, 2013

Sorry @allen-628, but I'm having trouble understanding what this issue is about. Please re-open if you're still having the issue and include a fiddle that demonstrates exactly what the problem is.

@pfiller pfiller closed this as completed Apr 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants