- Home
- Forum
- ASP.NET MVC
- use of Url.Action in Grid Column Templete
use of Url.Action in Grid Column Templete
Hi!
While implementing a grid column template for Action Link in syncfusion MVC, I have come across a problem where I am having trouble retrieving the primary key in Grid Column Template. My razor view code is given below.
@model List<Evolet.Domain.ViewModels.viewEmployee>
<h2> Employees Grid</h2>
@(Html.EJ().Grid<Evolet.Domain.ViewModels.viewEmployee>("EmployeeGrid")
.Datasource(Model)
.AllowSorting(true)
.AllowResizing(true)
.AllowPaging(true)
.AllowGrouping(true)
.AllowTextWrap(true)
.AllowScrolling(true)
.AllowFiltering()
.EnableRowHover(true)
.AllowSelection(false)
.IsResponsive(true)
.FilterSettings(filter => { filter.FilterType(FilterType.Excel); })
.Columns(col =>
{
col.Field(x => x.EmployeeID).HeaderText("ID").Visible(false).Width(30).IsPrimaryKey(true).AllowResizing(false).Add();
col.Field(x => x.EmployeeCode).HeaderText("Code").Width(60).AllowFiltering(true).Add();
col.Field(x => x.EmployeeName).HeaderText("Employee Name").Template("<a rel='nofollow' href = '" + Url.Action("EditEmployee", "SCM", new { id = "{{:EmployeeID}}" , status = ViewContext.RouteData.Values["id"] }) + "' data-req = {{:EmployeeID}} class='EditEmployee'>{{:EmployeeName}}</a>").Add();
})
)
i am unable to retrieve the primary key of the model to pass it as "id" parameter of my controller method, while using .Templete() method in grid column.
This is the rendered URL. http://localhost:64177/SCM.mvc/EditEmployee/{{%3aEmployeeID}}.
IT SHOULD HAVE PRIMARY KEY AS "id" PARAMETER.
Any help is appriciated
Thanx
Saud Nasir
SIGN IN To post a reply.
1 Reply
SA
Saravanan Arunachalam
Syncfusion Team
September 19, 2017 07:26 AM UTC
Hi Nasir,
Thanks for contacting Syncfusion’s support.
By default, the Url.Action method consider the id (which is render from JsRender template) as string and we can achieved your requirement by binding the onclick event for the template element. In the onclick event we have replaced that the string with corresponding value. Please refer to the below code example.
|
@(Html.EJ().Grid<object>("FlatGrid")
. . .
.Columns(col =>
{
. . .
col.Field(x => x.EmployeeName).HeaderText("Employee Name").Template("<a rel='nofollow' href = '" + Url.Action("EditEmployee", "SCM", new { id = "{{:EmployeeID}}", status = ViewContext.RouteData.Values["id"] }) + "' data-req = {{:EmployeeID}} id = {{:EmployeeID}} onclick='check({{:EmployeeID}})' class='EditEmployee'>{{:EmployeeName}}</a>").Add();
}))
<script type="text/javascript">
function check(val) {
//here we can assign the corresponding primarykey value as additional parameter
var str = $("#" + val).attr("rel='nofollow' href");
str.replace("{{%3aEmployeeID}}", val);
}
</script> |
Regards,
Saravanan A.
SIGN IN To post a reply.
- 1 Reply
- 2 Participants
-
SN Saud Nasir
- Sep 18, 2017 07:26 AM UTC
- Sep 19, 2017 07:26 AM UTC