HttpRequestValidationException Error when exporting.

Hi. I have a grid to which i added a column to implement record actions with icons, such as Edit and Delete, calling their respective actions in controller. The grid looks and works good, but when I try to export to excel, i get the following error:

A potentially dangerous Request.Form value was detected from the client (GridModel="...emplate":" " +
" ")
.Width("75").AllowFiltering(false)
.Add();
col.Field(p => p.Legajo).HeaderText("Legajo").Width("25%").Add();
col.Field(p => p.MedioLegajo).HeaderText("Medio Legajo").Width("25%").Add();
col.Field(p => p.Nombre).HeaderText("Nombre").Width("25%").Add();
col.Field(p => p.Nombre).HeaderText("Nombre 2").Width("25%").Add();
col.Field(p => p.NumTarjeta).HeaderText("Tarjeta N°").Width("25%").Add();
col.Field(p => p.NumTarjeta).HeaderText("Tarjeta N° 2").Width("25%").Add();
col.Field(p => p.TipoRegistroDescrip).HeaderText("Tipo Registro").Width("25%").Add();
})

So, what could be wrong with it?
Is this the best way to achieve the command column to call actions (with icons) ?

Thank you.


3 Replies

AS Alan Sangeeth S Syncfusion Team October 18, 2017 05:44 AM UTC

Hi Pablo, 

We analyzed the reported query and found that the script throws because of the HTML Elements in the Grid model. In the Grid, you may have given HTML Elements in the Template (of Columns). It is the root cause of the problem which prevents the exporting and throws an exception.   
  
To overcome this problem, we suggest you set the validateRequest property of pages as false and requestvalidationMode as “2.0” (of httpRunTime) in web.config file. Please refer to the below code example.    
   
  <system.web>  
    <httpRuntime requestValidationMode="2.0" />  
    <pages validateRequest="false"/>  
  </system.web>  
 
  
Please refer to the below online links where this query has been discussed.    
   
     
   
  
If you are not willing to reconfigure the web.config page, you can assign an ID to the Template (of Columns) as shown in the following code example.  
  
            <script type="text/template" id="Template">  
                <a rel='nofollow' href='market.aspx?id={{:id}}'>{{:name}}</a>  
            </script>  
 @(Html.EJ().Grid<EmployeeView>("ColumnTemplate") 
        .Datasource((IEnumerable<object>)ViewBag.datasource) 
        .AllowPaging() 
        .PageSettings(page => { page.PageSize(4); }) 
        .Columns(col => 
        { 
            col.HeaderText("Employee Image").Template("#Template").TextAlign(TextAlign.Center).Width(110).Add(); 
 
}) 
        ) 
 
  

Regards, 
Alan Sangeeth S 



PM Pablo Maloberti October 18, 2017 03:17 PM UTC

Thanks, it worked with the template id!



MS Mani Sankar Durai Syncfusion Team October 19, 2017 04:12 AM UTC

Hi Pablo, 
 
We are happy to hear that your problem has been solved. 
 
Please let us know if you need further assistance. 
 
Regards, 
Manisankar Durai. 
 



Loader.
Up arrow icon