We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

use of Url.Action in Grid Column Templete

Thread ID:

Created:

Updated:

Platform:

Replies:

132721 Sep 18,2017 03:26 AM Sep 19,2017 03:26 AM ASP.NET MVC 1
loading
Tags: Grid
Saud Nasir
Asked On September 18, 2017 03:26 AM

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 

Saravanan Arunachalam [Syncfusion]
Replied On September 19, 2017 03:26 AM

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. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;