Вы можете использовать AJAX.Но сначала давайте улучшим ваш код, избавившись от этих циклов и заменив их шаблонами отображения:
@model IEnumerable<SomeViewModel>
<table>
<thead>
<tr>
<th>Title</th>
<th>Body</th>
<th>Price</th>
<th>actions ...</th>
</tr>
</thead>
<tbody>
@Html.DisplayForModel()
</tbody>
</table>
<div id="details"></div>
, а затем определим шаблон отображения (~/Views/Shared/DisplayTemplates/SomeViewModel.cshtml
):
@model SomeViewModel
<tr>
<td>@Html.DisplayFor(x => x.Title)</td>
<td>@Html.DisplayFor(x => x.Body)</td>
<td>@Html.DisplayFor(x => x.Price)</td>
<td>
<!-- no idea what the purpose of this *noteid* attribute on the span is
but this is invalid HTML. I would recommend you using the
HTML5 data-* attributes if you wanted to associate some
metadata with your DOM elements
-->
<span class="EditLink ButtonLink" noteid="@Model.Id">
Edit
</span>
|
<span>
@Html.ActionLink("Delete", "Delete", new { id = Model.Id })
</span>
|
@Html.ActionLink(
"Detalji", // linkText
"Details", // actionName
null, // controllerName
new { id = Model.Id }, // routeValues
new { @class = "detailsLink" } // htmlAttributes
)
</td>
</tr>
Теперьвсе, что осталось, это AJAX, уточнить эту ссылку в отдельном файле javascript:
$(function() {
$('.detailsLink').click(function() {
$('#details').load(this.href);
return false;
});
});
Что, конечно, предполагает, что у вас есть следующее действие:
public ActionResult Details(int id)
{
SomeDetailViewModel model = ... fetch the details using the id
return PartialView(model);
}