我有 MVC 应用程序。有一个视图包含一些属性和评论链接。当用户点击评论链接时,评论 div 会展开,所有评论都会显示给用户。现在我想自动化该功能,或者我可以说想跳过该点击过程,当用户看到该视图时,所有评论都应该出现。(无需点击链接,所有评论都应显示)
怎么做 ?
查看代码
@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>