ASP.NET Core grid defaultValue taghelper does not compile

I am able to provide a defaultValue for a boolean column but not a literal for a string column.

This compiles:

<e-grid-column field="AnnualGivingInd" headerText="Annual Giving" displayAsCheckBox="true" textAlign="Center" editType="booleanedit" type="boolean" defaultValue="false" validationRules="@(new { required = true })"></e-grid-column>

This does not compile with error "The name 'A' does not exist in the current context":

 <e-grid-column field="CampusCode" headerText="Campus Code" defaultValue="A" type="string"></e-grid-column>

The example in the documentation looks pretty straightforward (https://ej2.syncfusion.com/aspnetcore/documentation/grid/edit/):

        <e-grid-column field="CustomerID" headerText="Customer ID"  defaultValue="HANAR" type="string" width="120"></e-grid-column>                

How can I default a literal for a string?


3 Replies 1 reply marked as answer

MS Manivel Sellamuthu Syncfusion Team November 11, 2020 04:36 PM UTC

Hi Harvey, 

Greetings from Syncfusion support. 

We have validated your requirement. You can achieve your requirement by defining a value for the variable . Please refer the below code example for more information. 

 
@{  
    var strvalue = "sefsf"; 
} 
 
<div> 
    <ejs-grid id="Grid" dataSource="ViewBag.DataSource" toolbar="@(new List<string>() { "Add", "Edit", "Delete","Update","Cancel" })" allowPaging="true"> 
        <e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true"></e-grid-editSettings> 
        <e-grid-columns> 
            
            <e-grid-column field="CustomerID" defaultValue="@strvalue" headerText="Customer Name" width="150"></e-grid-column> 
             . . . 
        </e-grid-columns> 
    </ejs-grid> 
</div> 

Please let us know, if you need further assistance. 

Regards, 
Manivel 


Marked as answer

HK Harvey Kravis November 11, 2020 05:44 PM UTC

Works like a charm!  Thanks!


MS Manivel Sellamuthu Syncfusion Team November 12, 2020 04:33 AM UTC

Hi Harvey, 

Thanks for your update. 

We are glad that the provided solution worked. 

Please let us know, if you need further assistance. 

Regards, 
Manivel 


Loader.
Up arrow icon