C#

[.net MVC]PartialView 호출하는 방법

[MainController]
public PartialViewResult MainDocumentPartial()
{
   int Year = DateTime.Now.Year;
   var model = _repository.FindAll<DocumentListModel, int>(“GetList”, Year);
   return PartialView(model);
}

[main.cshtml]
$(document).ready(function () {
   $(“.ajax_partial”).each(function (index, item) {
     var url = $(item).data(“url”);
     if (url && url.length > 0) {
       $(item).load(url);
     }
  });
});

 

< h2>오픈 안내< /h2>
< div class=”ajax_partialdata-url=”/Main/MainDocumentPartial”>
@Html.Partial(“LoadingCircle”)
< /div>

[MainDocumentPartial.cshtml]
@model IEnumerable<Model.View.DocumentListModel>

< table summary=”오픈 안내” class=”list_type”>
< colgroup>
< col style=”width: 50%;” />
< col style=”width: 50%;” />
< /colgroup>
< thead>
< tr>
< th>제목< /th>
< th>등록일< /th>
< /tr>
< /thead>
< tbody>
@if (Model != null && Model.Count() > 0)
{
   var i = 1;
   foreach (var item in Model)
  {
< tr class=@(i % 2 == 0 ? “even” : “”)>
< td>
@Html.ActionLink(item.Title, “DocumentDetail”, “Main”, new { id = item.DocumentID }, null)
< /td>
< td>@item.RegDate < / td>
< /tr>
i++;
}

}
else
{
   < tr>
   < td colspan=”2″>
   < label style=”color:Red;font-weight:bolder;”>-< /label>
   < /td>
   < /tr>
}
< /tbody>
< /table>

Leave a Reply

error: Content is protected !!