Reputation: 117
I'm uisng MVC3 with MVCContrib to display my grids. A column in the grid is a star rater.
Below is my code showing how im calling my user rate and my jquery.
My problem is that the stars for the rate is only showing on the first record and not all the records.
Can someone help ? .. please
<div id="grid">
@{
Html.Grid(Model).Columns(column =>
{
column.For(c => c.taUserName).Named("Agent").HeaderAttributes(@class => "gridheader").Attributes(style => "width:15%");
column.Custom(@<div id="star-rating">
<input type="radio" name="@column.For(c => c.userRate)" class="rating" value="1" />
<input type="radio" name="@column.For(c => c.userRate)" class="rating" value="2" />
<input type="radio" name="@column.For(c => c.userRate)" class="rating" value="3" />
<input type="radio" name="@column.For(c => c.userRate)" class="rating" value="4" />
<input type="radio" name="@column.For(c => c.userRate)" class="rating" value="5" />
</div>);
}).Render();
}
</div>
<script type="text/javascript">
$(function () { // Start when document ready
$('#star-rating').each(function () {
//Get the hidden field data and set it to the rating plugin
$(this).rating();
}); // Call the rating plugin
});
</script>
Upvotes: 0
Views: 339
Reputation: 917
As mentioned in the comments, IDs should be unique. Switching to a class will solve your problem.
Another way that should work (but using a class is definitely a better option), is to select using the attribute selector with the id being the attribute: $("[id='star-rating']") That selector will select all elements with the specified id instead of only the first one.
Upvotes: 1