我正在使用这个网站的网格源代码:
http://gridmvc.azurewebsites.net/
但我不明白查询字符串是如何为他的自定义列形成的。在我提供的链接上有一个编辑列,如果您将鼠标悬停在链接上,您可以看到带有查询字符串 ID 的超链接。我已经使用了这个源代码,但没有适合我的查询字符串。
控制器代码
#region PartialViews
[ChildActionOnly]
public ActionResult RenderGrid()
{
DataLayer.RepositoryClient RC = new RepositoryClient();
var People = RC.GetPeople();
return PartialView("~/Views/Client/PartialViews/P_PersonGrid.cshtml", People);
}
#endregion
我从实体框架中获得了一份人员名单。然后我在局部视图中使用模型列表。
局部视图
@model List<Models.modelPeopleGrid>
@using GridMvc.Html
@{
ViewBag.Title = "Person records";
}
<div>
@Html.Label("Search for person")
<input type="text" onkeyup="activateSearch()" id="txtSearch" style="width:150px";/>
</div>
<div class="grid-wrap" style="float:left">
@Html.Grid(Model).Named("peopleGrid").Columns(columns =>
{
columns.Add(m => m.Firstname).Titled("Firstname").Filterable(true);
columns.Add(m => m.Surname).Titled("Surname").Filterable(true);
columns.Add(m => m.DateOfBirth).Titled("DateOfBirth").Filterable(true);
columns.Add(m => m.Address).Titled("Address").Filterable(true);
columns.Add(m => m.Borough).Titled("Borough").Filterable(true);
columns.Add(m => m.PersonID).Encoded(false).Sanitized(false).SetWidth(30).RenderValueAs(
@<b>
@Html.ActionLink("Edit person details", "EditPerson", "Index")
</b>);
columns.Add()
.Encoded(false)
.Sanitized(false)
.SetWidth(30)
.RenderValueAs(m =>
@<b>
@Html.ActionLink("Add/remove claims", "EditClaim", "Index")
</b>);
}).WithPaging(20)
</div>
<div class="rowValues" style="float:right"></div>
<script>
$(function () {
pageGrids.peopleGrid.onRowSelect(function (e) {
$(".rowValues").html(
"<h4>Full details of person:</h4>" +
"Firstname: " + e.row.Firstname + "<br />" +
"Surname: " + e.row.Surname + "<br />" +
"DateOfBirth: " + e.row.DateOfBirth + "<br />" +
"Address: " + e.row.Address + "<br />" +
"Borough: " + e.row.Borough + "<br />"
);
});
});
</script>
<script type="text/javascript">
function activateSearch() {
var value = $("#txtSearch").val();
$.ajax({
url: "Client/GetPeople",
dataType: 'html',
type: "GET",
data: { Name: value },
success: function (data) {
$('.webgrid').empty().html(data);
},
error: function () {
alert("error");
}
});
}
</script>
我不知道如何获取为这行代码形成的查询字符串:
columns.Add(m => m.PersonID).Encoded(false).Sanitized(false).SetWidth(30).RenderValueAs(
@<b>
@Html.ActionLink("Edit person details", "EditPerson", "Index")
</b>);
我尝试将 html 对象属性作为 actionlink 的第四个参数,但由于某种原因,我得到了一个红色的 swiggly。
有人知道如何回答我的问题吗?