Question

I am using DataTables with jquery AJAX and Entity Framework . I return EntityFramework object from a webmethod which serializes it to json . I have lot of tables for which I need to generate CRUD pages , so in backend page there will be CRUD webmethods . I was doing that previously with dynamic data . Is there any way do generate those pages using T4 Templates ? I dont have exact code at the moment but end result will be something like this

http://editor.datatables.net/release/DataTables/extras/Editor/examples/envelope_inline.html

Here is some example Code in .aspx.cs which returns json

    [WebMethod]
    public string GetCustomers(int page)
    {
       return db.Customers.Skip(page*100).Take(100);
    }

   [WebMethod]
    public string DeleteCustomer(int id)
    {
        // ...
    }

On .aspx page

$(document).ready(function() {
    var oTable = $('#example').dataTable( {
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "scripts/server_processing.aspx"            
        }
    } );
} );
Was it helpful?

Solution

Sure you can do it like this:

<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension="aspx.cs" #>
<# var crudObject= "Customer";
var plural = crudObject+"s"; #>

[WebMethod]
public string Get<#=plural#>(int page)
{
   return db.<#=plural#>.Skip(page*100).Take(100);
}

[WebMethod]
public string Delete<#=crudObject#>(int id)
{
    // ...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top