0

I'm working on a website where the owner has exhibitions which he can add, edit and delete. The exhibitions are showed per year, once clicking on the 'Read more' button. I'm running into a weird problem with my pages, since I'm loading the content in a new div once clicking on 'Read more' and I need an unique identifier for this div. I'm using id="@Year here" to identify this div, however I run into this problem:

enter image description here

As you can see, it is not loading properly. I have the following code to load in all exhibitions per group:

@if(Model.Exhibitions.Count() > 0)
{
<h3 style="text-align: left; margin-left: 10px; padding-top: 10px;">@Model.Year</h3>
<table class="extable">
    <tr>
        <th style="width: 15%">@Translations.EXHIBITIONSTARTDATE</th>
        <th style="width: 15%">@Translations.EXHIBITIONENDDATE</th>
        <th style="width: 15%">@Translations.EXHIBITIONEVENT</th>
        <th style="width: 40%">@Translations.EXHIBITIONDESCRIPTION</th>
        <th style="width: 15%">@Translations.GALLERY</th>
    </tr>

@foreach (Exhibition item in Model.Exhibitions)
{
    @Html.Partial("_Exhibition", item)
}

</table>

}

<div class="more-exhi" id="@Model.Next"></div>

<script type="text/javascript">
(function () {
    $('.more-exhi#@Model.Year').attr('class', '');
    $('.show-more').attr('data-year', '@Model.Next');
}) ();
</script>

@Model.Year is the year being send to the controller (for example, 2014). @Model.Next is the next existing year with exhibitions in descending order (for example, 2010). However the code is above is not working right, and I am not sure why. This is my javascript once someone clicks on the button 'Read more':

<script type="text/javascript">

(function () {

    var div = $('#exhibitions');

    div.find('.show-more').click(function () {
        div.find('.more-exhi').hide().load('@Url.Action("Exhibitions", "Exhibition")', { year: $(this).attr('data-year') } ).fadeIn('1500');
        div.find('.show-less').show();
    });

})();
</script>

Could someone help me fixing this problem? I think I'm overseeing a problem here, as this shouldn't be too difficult.

1 Answer 1

4

Try to change this line of code into:

 $('.more-exhi#' + @Model.Year).attr('class', '');

:)

Sign up to request clarification or add additional context in comments.

1 Comment

No prob, @KevinVoorn!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.