0

I have MVC application. There is one view which contains some properties and the comment link. when user click on comment link, comment div get expands and all comment are shown to user. now I want to automate that function or I can say want to skip that clicking process, when user see that view all comments should appear. (without clicking on a link all the comment should be shown )

how to do that ?

View Code

            @model PaymentAdviceEntity.Employee

            @{
                ViewBag.Title = "Edit";
            }

            <h2>Edit</h2>

            <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
            <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>

            @using (Html.BeginForm()) {
                @Html.ValidationSummary(true)
                   <div class="row-fluid">

                <fieldset>


                    @Html.HiddenFor(model => model.Id)



                    <div class="editor-label span3">
                        @Html.LabelFor(model => model.FirstName,"First Name")
                    </div>
                    <div class="editor-field span3 InputBoxMargin">
                        @Html.EditorFor(model => model.FirstName)
                        @Html.ValidationMessageFor(model => model.FirstName)
                    </div>


                          <div class="editor-label span3">
                          @Html.LabelFor(model => model.LastName,"Last Name")
                          </div>
                          <div class="editor-field span3 InputBoxMargin">
                          @Html.EditorFor(model => model.LastName)
                          @Html.ValidationMessageFor(model => model.LastName)
                          </div>
                       </div>
               </div>
            </div>
                     </fieldset>
            </div>

                     <div>
                      <p>
                        <input type="submit" value="Save" />
                    </p>
                 </div>

<div>


     <span>@Ajax.ActionLink("Comments", null, null, null, new { id = Model.Id, @class = "addremark" })</span>

        <div class="RemarkBox"></div>
        <span class="CommentAdd"></span>

</div>

            }



    $(document).ready(function () {
    //$('.RemarkBox').hide();
    $('a.addremark').click(function (event) {
    ar url = "@Html.Raw(Url.Action("ShowCommentBox", "Comment", new { Id = "idValue", EntityType = "Employee" }))";
     url = url.replace("idValue", event.target.id);
     $('.RemarkBox').load(url);
     $(this).closest('div').find('div.RemarkBox').slideToggle();
     return false;
     });  
     }); 
       </script>
Daniel Imms
  • 47,944
  • 19
  • 150
  • 166
Nil
  • 133
  • 2
  • 7
  • 23

1 Answers1

1

Try something like this, the main part being you need to call the click function in your document ready.

$(document).ready(function () {
    $('a.addremark').click(addremarkClick);

    // Call on load also
    addremarkClick();
});

function addremarkClick(event) {
    var url = '@Html.Raw(Url.Action("ShowCommentBox", "Comment", new { Id = "idValue", EntityType = "Employee" }))';

    if (typeof event !== 'undefined') url = url.replace("idValue", event.target.id);
    else url = url.replace("idValue", $('a.addremark')[0].id);

    $('.RemarkBox').load(url);
    $(this).closest('div').find('div.RemarkBox').slideToggle();
    return false;
}
Daniel Imms
  • 47,944
  • 19
  • 150
  • 166