Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Telerik MVC Extensions (superseded) > General Discussions > client template Razor

Not answered client template Razor

Feed from this thread
  • Nebras avatar

    Posted on Jun 19, 2011 (permalink)

    Hello Telerik Team,
    I need to create a column in MVC 3 grid which is a button and I want it to redirect the user to an action called "edit " in the "home" controller 
    I tried this:
     columns.Bound(c => c.Id).ClientTemplate(" <input type=\"button\" onclick=\"parent.location='@Url.Action(\"Edit\", \"Home\")'\" value=\"Edit\" />");
    
    but it doesn't work , why ?
    
    also, I need to pass the whole object(record) to the action , what can I do?

    Reply

  • Atanas Korchev Atanas Korchev admin's avatar

    Posted on Jun 20, 2011 (permalink)

    Hi Nebras ,

    Does your code work outside of the grid? What is the value generated for the onlick attribute at runtime? If it does not you can try this:

    onclick="location.href= "

    instead of 

    onclick="parent.location"

    You cannot pass the whole model to your action method - you can only pass a few properties:

    '@Url.Action(\"Edit\", \"Home\", new { ModelProperty=\"<#= ModelProperty #>\" })'\"

    Regards,

    Atanas Korchev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Nebras avatar

    Posted on Jun 20, 2011 (permalink)

    Thanks Atanas  for your  reply,
    but this also doesn't work 

    Reply

  • Atanas Korchev Atanas Korchev admin's avatar

    Posted on Jun 20, 2011 (permalink)

    Hello Nebras ,

     Which does not work? Could you be more specific? I need you to show us what the generated HTML is after binding a cell. If this is not possible you can provide a sample project which we can test.

    Regards,
    Atanas Korchev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Nebras avatar

    Posted on Jun 20, 2011 (permalink)

    sorry for confusion ,
    the template I used
     columns.Bound(c => c.Id).ClientTemplate(" <input type=\"button\" onclick=\"location.href='@Url.Action(\"Edit\", \"Allergy\", new { id=\"<#= Id #>\" })'\" value=\"Edit\" />");
    
    the generated html is
     <input id="38" onclick="location.href='@Url.Action(" type="button" })??="" {="" new="" ?Allergy?,="" Edit?,="" value="Edit"/>

    Reply

  • Atanas Korchev Atanas Korchev admin's avatar

    Posted on Jun 20, 2011 (permalink)

    Hi Nebras ,

     It is obvious that it won't work because Url.Action is output without being executed. Url.Action is server side code and you need to execute it on the server. I suggest you check the client-templates online example which shows how to embed server side calls inside a client template. Here is an excerpt:

    columns.Bound(c => c.CustomerID)
                    .ClientTemplate("<img alt='<#= CustomerID #>' src='"
                        + Url.Content("~/Content/Grid/Customers/")
                        + "<#= CustomerID #>.jpg' />")
                    .Title("Picture");
    The idea is to execute the server side code first and then use its value in the client-side template definition.

    Regards,
    Atanas Korchev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • Kamau avatar

    Posted on Jul 26, 2011 (permalink)

    How does this work when using URL.Action? For instance:
    columns.Bound(user => user.Username).ClientTemplate("<#= <a href='" +  Url.Action("EditUser", "CreateEditUser", new {username = user.Username}) + " '>Username</a>  #>");

    In this case, the anonymous type parameter to URL.Action seems that sets the value of username, is unable to be set, as there isnt an obvious way to escape to the context of the current row, and extract that value from user.

    Is this possible?

    Reply

  • Rosen Rosen admin's avatar

    Posted on Jul 27, 2011 (permalink)

    Hi Kamau,

    As my college Atanas showed, you should use a slightly different syntax, similar to the following:

    .ClientTemplate("<a href='" +  Url.Action("EditUser", "CreateEditUser", new {username = "<#=Username#>"}) + " '>Username</a>  ")

    Greetings,
    Rosen
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

    Reply

  • yashwanth krishna avatar

    Posted on Oct 3, 2011 (permalink)

    I wanted to place an datepicker in the grid Using Editor Template..Is it possible and How can i place it??

    Reply

  • Keerthi avatar

    Posted on Oct 15, 2012 (permalink)

    Parameter that I'm passing in the Url has special characters. How to encode the parameter?

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Telerik MVC Extensions (superseded) > General Discussions > client template Razor