Asp.net mvc 4 在ASP.NET MVC中为KendoUI网格控件中的每一行添加包含超链接的列

Asp.net mvc 4 在ASP.NET MVC中为KendoUI网格控件中的每一行添加包含超链接的列,asp.net-mvc-4,kendo-ui,Asp.net Mvc 4,Kendo Ui,以下是我的视图,其中包含KendoUI网格控件: 我想添加一个新列,其中包含创建列日期之前的超链接 @using Kendo.Mvc.UI @model IEnumerable<ExamplekendoDropdown.Models.FacilityGroup> @{ ViewBag.Title = "Grid"; } <table width="700"> <tr> <td align="center"> <tab

以下是我的视图,其中包含KendoUI网格控件: 我想添加一个新列,其中包含创建列日期之前的超链接

@using Kendo.Mvc.UI 
@model IEnumerable<ExamplekendoDropdown.Models.FacilityGroup>



@{
    ViewBag.Title = "Grid";
}



<table width="700">
<tr>
<td align="center">


<table width="1000">
<tr>
<td align="left">
@using (Html.BeginForm("Grid", "Grid", FormMethod.Get))

{
    <table>
    <tr>
    <td>
    <span>Facility Group Name</span>
    </td>
    <td>
    @(Html.Kendo().AutoComplete()
                   .Name("FacilityGroupName")
                   .Value("")
                   .Enable(true)
                ) 
    @Html.Hidden("FacilityGroupName")
    </td>
    </tr>
    <tr>
    <td>
    <input id="Submit1" type="submit" value="Search" />
    </td>
    </tr>
    </table>
}

</td>
</tr>
<tr>
<td align="center" >
@(Html.Kendo().Grid(Model)
    .Name("Grid")

    .Columns(columns =>
        {
                columns.Bound(p => p.FacilityGroupId);

                    //columns.Bound(@Html.ActionLink("Create Facility", "Facility"));


                columns.Bound(p =>p.FaclityGroupName);
                columns.Bound(p => p.status).Width(80);
                columns.Bound(p => p.CreationDate);
                columns.Command(command => { command.Edit();  });
        })

        //.ToolBar(toolbar =>toolbar.Create())
        //.Editable(editable => editable.Mode(GridEditMode.PopUp))

        .Editable(editable => editable.Mode(GridEditMode.PopUp).TemplateName("EditUserPopupTemplate")
            .Window(w => w.Title("Facility").Name("editWindow").Width(300).Height(300)))
        .Pageable()
        .Sortable()
        .Scrollable()
        .DataSource(datasource => datasource
            .Server()
            .Model(model => model.Id(p => p.FacilityGroupId ))
            .Read("Grid", "Grid")
            .Update("Update", "Grid")

            //.Create("Create","Grid")
            //.Destroy("Destroy","Grid")
            )
                )

<script type="text/javascript">
    $(document).ready(function () {
        $("form.k-edit-form").kendoValidator();
    });

</script>

</td>
</tr>
</table>


 </td>
</tr>
</table>
@使用Kendo.Mvc.UI
@模型IEnumerable
@{
ViewBag.Title=“网格”;
}
@使用(Html.BeginForm(“Grid”、“Grid”、FormMethod.Get))
{
设施组名称
@(Html.Kendo().AutoComplete())
.名称(“设施组名称”)
.价值(“”)
.Enable(真)
) 
@Html.Hidden(“FacilityGroupName”)
}
@(Html.Kendo().Grid(模型)
.名称(“网格”)
.列(列=>
{
columns.Bound(p=>p.FacilityGroupId);
//columns.Bound(@Html.ActionLink(“创建设施”、“设施”));
columns.Bound(p=>p.FaclityGroupName);
columns.Bound(p=>p.status).Width(80);
columns.Bound(p=>p.CreationDate);
Command(Command=>{Command.Edit();});
})
//.ToolBar(ToolBar=>ToolBar.Create())
//.Editable(可编辑=>Editable.Mode(GridEditMode.PopUp))
.Editable(Editable=>Editable.Mode(GridEditMode.PopUp).TemplateName(“EditUserPopupTemplate”)
.窗口(w=>w.标题(“设施”).名称(“编辑窗口”).宽度(300).高度(300)))
.Pageable()
.Sortable()
.Scrollable()
.DataSource(DataSource=>DataSource
.Server()
.Model(Model=>Model.Id(p=>p.FacilityGroupId))
.阅读(“网格”、“网格”)
.更新(“更新”、“网格”)
//.创建(“创建”、“网格”)
//.销毁(“销毁”、“网格”)
)
)
$(文档).ready(函数(){
$(“form.k-edit-form”).kendoValidator();
});
现在,我需要在包含超链接的“创建日期”列之前添加另一列。 请分享你的意见
谢谢

您可以使用Template和ClientTemplate来获取包含超链接的列

columns.Bound(p => p.CreationDate)
    .Template(@<text><a href="">@item.CreationDate</a></text>)
    .ClientTemplate("<a href=''>#CreationDate<a/>").Title("Link");
columns.Bound(p => p.CreationDate);
columns.Bound(p=>p.CreationDate)
.模板(@)
.ClientTemplate(“创建日期”).Title(“链接”);
columns.Bound(p=>p.CreationDate);

您只需要使用模板方法进行服务器绑定。(ClientTemplate用于Ajax绑定)。您不需要将其绑定到特定属性,除非您希望将列标题与该属性的filter/sort/group相关联

columns.Template(@<text>@Html.ActionLink("Create Facility", "Facility")</text>)
columns.Template(@@Html.ActionLink(“创建工具”、“工具”))
列。模板(@)
.ClientTemplate(“”)
.HtmlAttributes(新的{style=“text align:left;”})
.宽度(60);

这对我来说很有效,但是如果你使用的是ajax,为什么不这样做呢

Ajax().ClientTemplate("<a href='" + Url.Action("YourAction", "YourController") +"/#= Id #'" +">#=FileName#</a>");

if server()
columns.Bound(p => p.ProductID).Template(@<text>
                 @Html.ActionLink("Show Product Details", "ProductDetails", new { id = @item.ProductID } )>
                 </text>);
Ajax().ClientTemplate(“”);
if服务器()
columns.Bound(p=>p.ProductID).Template(@
@ActionLink(“显示产品详细信息”,“产品详细信息”,新建{id=@item.ProductID})>
);

columns.Template(@).ClientTemplate(
@ActionLink(“发送重置电子邮件”,“登录”,新建{loginButton=“重置”,activate=true,fromAdmin=true,rowField=“#=rowField#”})。ToHtmlString()
);

这对我很有用。

如果您的网格具有服务器绑定,请使用以下选项:

  columns.Bound(x => x.ProjectCode)
          .Template(items => Html.ActionLink(items.ProjectCode, "Manage", "Project", new {projectId = items.ProjectId}, null));

此语法仅适用于服务器绑定。查看网格上的常见问题,它们都在那里。感谢您提供他们常见问题的链接!我喜欢这个答案中的随机格式。这是懒散的高度。
columns.Template(@<text></text>).ClientTemplate(
    @Html.ActionLink("Send Reset Email", "Login", new { loginButton = "reset",activate=true,fromAdmin=true,rowField="#=rowField#" }).ToHtmlString()
);
  columns.Bound(x => x.ProjectCode)
          .Template(items => Html.ActionLink(items.ProjectCode, "Manage", "Project", new {projectId = items.ProjectId}, null));