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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Grid Edit Template sends null value to controller when adding new record

Thread ID:

Created:

Updated:

Platform:

Replies:

141380 Dec 8,2018 09:59 AM UTC Dec 13,2018 04:10 AM UTC ASP.NET Core 5
loading
Tags: Grid
Jordi
Asked On December 8, 2018 09:59 AM UTC

Following code works fine when updating a record, but it sends a null value to controller when inserting a new record. I'm not able to find the problem. Thank you

<ej-grid id="FlatGrid" allow-paging="false" is-responsive="true" enable-responsive-row="true" action-complete="complete" action-failure="failure">
    <e-datamanager json="@ViewBag.JornadesCampionat" insert-url="/Jornades/Insert" update-url="/Jornades/Update" remove-url="/Jornades/Remove" adaptor="remoteSaveAdaptor"></e-datamanager>
    <e-toolbar-settings show-toolbar="true" toolbar-items=@(new List<string>() {"add","edit","delete","update","cancel" })></e-toolbar-settings>
    <e-edit-settings allow-adding="true" allow-editing="true" allow-deleting="true" show-delete-confirm-dialog="true" edit-mode="InlineFormTemplate" inline-form-template-id="#template" />
    <e-columns>
        <e-column field="JornadaID" header-text="JornadaID" text-align="Left" is-identity="true" is-primary-key="true" default_value="0" visible="false"></e-column>
        <e-column field="Descripcio" header-text="Descripcio" text-align="Left" visible="true"></e-column>
        <e-column field="CampionatID" header-text="CampionatID" text-align="Left" default-value="@ViewBag.CampionatIDConsulta" visible="false"></e-column>
        <e-column field="DataIniciJornadaUTC" header-text="Inici" text-align="Left" format="{0:dd/MM/yy HH:mm}" edit-type="DateTimePicker"> <ej-date-picker allow-edit="true"></ej-date-picker></e-column>
        <e-column field="DataIniciApostesUTC" header-text="IniciApostes" text-align="Left" format="{0:dd/MM/yy HH:mm}" edit-type="DateTimePicker" visible="true"> <ej-date-picker allow-edit="true"></ej-date-picker></e-column>
        <e-column field="DataFinalitzacioApostesUTC" header-text="FiApostes" text-align="Left" format="{0:dd/MM/yy HH:mm}" edit-type="DateTimePicker" visible="true"> <ej-date-picker allow-edit="true"></ej-date-picker></e-column>
        <e-column field="PermesApostar" header-text="PermesApostar" edit-type="BooleanEdit" default-value="true" text-align="Left" visible="true"></e-column>
        <e-column field="Finalitzada" header-text="Finalitzada" edit-type="BooleanEdit" default-value="false" text-align="Left" visible="true"></e-column>
        <e-column header-text="" Template="<a rel='nofollow' rel='nofollow' href='../ApostesJornada?JornadaID={{:JornadaID}}'>Apostes</a>"></e-column>
    </e-columns>

</ej-grid>



<script id="template" type="text/template">
    <input id="JornadaID" name="JornadaID" value="{{:JornadaID}}" hidden="hidden" />
    <input id="CampionatID" name="CampionatID" value="{{:CampionatID}}" hidden="hidden" />
    <table cellspacing="10">
        <tr>
            <td>Descripcio</td>
            <td>
                <input id="Descripcio" name="Descripcio" value="{{:Descripcio}}" class="e-field e-ejinputtext" style="width:200px;height:28px" />
            </td>
        </tr>
        <tr>
            <td>Inici Jornada</td>
            <td>
                <input id="DataIniciJornadaUTC" name="DataIniciJornadaUTC" value="{{:DataIniciJornadaUTC}}" />
            </td>
        </tr>
        <tr>
            <td>Inici Apostes</td>
            <td>
                <input id="DataIniciApostesUTC" name="DataIniciApostesUTC" value="{{:DataIniciApostesUTC}}" />
            </td>
        </tr>
        <tr>
            <td>Fi Apostes</td>
            <td>
                <input id="DataFinalitzacioApostesUTC" name="DataFinalitzacioApostesUTC" value="{{:DataFinalitzacioApostesUTC}}" />
            </td>
        </tr>
        <tr>
            <td>Permès Apostar</td>
            <td>
                {{if PermesApostar}}
                <input id="PermesApostar" name="PermesApostar" type="checkbox" class="e-field e-checkbox" checked="checked">
                {{else}}
                <input id="PermesApostar" name="PermesApostar" type="checkbox" class="e-field e-checkbox">
                {{/if}}
            </td>
        </tr>
        <tr>
            <td>Finalitzada</td>
            <td>
                {{if Finalitzada}}
                <input id="Finalitzada" name="Finalitzada" type="checkbox" class="e-field e-checkbox" checked="checked">
                {{else}}
                <input id="Finalitzada" name="Finalitzada" type="checkbox" class="e-field e-checkbox">
                {{/if}}
            </td>
        </tr>
    </table>
</script>


Vignesh Natarajan [Syncfusion]
Replied On December 11, 2018 02:21 AM UTC

Hi Jordi, 
 
Thanks for using Syncfusion products. 
 
From your query, we understand that you are facing issue while adding a record a new record. Reported issue may occur due to below reasons, so kindly ensure the follow scenarios at your end. 
 
  1.  Ensure that you have used “value” parameter in the insert method of insert-url in the server side.
  2. Ensure that you have [FromBody] tag along with the Model class in the insert method.
 
IF you are still facing the issue. Kindly share the following details which will be helpful for us to validate the reported issue at our end. 
 
  1. Share the server side code example (update / insert /delete methods)
  2. Share the screenshot of post sent to server while adding in the Network tab of developer tools.
  3. Check whether  is there any script error in console window (if yes share the screenshot).
  4.  Share your essential studio version (xx.x.x.xx)
 
Regards, 
Vignesh Natarajan 


Jordi
Replied On December 11, 2018 07:10 PM UTC

Hi Vignesh,

Thank you for your response. I attach you the requested code details as I have checked that I used "value" parameter in the insert method and the use of FromBody tag along with the model.

Regards,

Jordi,



1 Server side code

public ActionResult Insert([FromBody]CRUDModel<Jornada> value)
{
try
{

var campionat = _context.Campionats.SingleOrDefault(c => c.CampionatID == value.Value.CampionatID);
if (campionat == null)
{
return NotFound();
}


var _up = new Infrastructure.UsuarisPenyaObject(_context, _userManager.GetUserId(HttpContext.User), campionat.PenyaID);

if (_up != null)
{

if (_up.Role() == "AdministradorPenya")
{
Jornada jornada = new Jornada
{
Descripcio = value.Value.Descripcio,
DataIniciJornadaUTC = value.Value.DataIniciJornadaUTC,
DataIniciApostesUTC = value.Value.DataIniciApostesUTC,
DataFinalitzacioApostesUTC = value.Value.DataFinalitzacioApostesUTC,
PermesApostar = value.Value.PermesApostar,
Finalitzada = value.Value.Finalitzada,
CampionatID = value.Value.CampionatID
};

_context.Jornades.Add(jornada);

_context.SaveChanges();

return Json(value.Value);
}
}

return BadRequest();
} catch(Exception e)
{
throw new Exception(e.InnerException.Message);
}

}

public ActionResult Update([FromBody]CRUDModel<Jornada> value)
{
try
{
var campionat = _context.Campionats.SingleOrDefault(c => c.CampionatID == value.Value.CampionatID);
if (campionat == null)
{
return NotFound();
}

var _up = new Infrastructure.UsuarisPenyaObject(_context, _userManager.GetUserId(HttpContext.User), campionat.PenyaID);

if (_up != null)
{

if (_up.Role() == "AdministradorPenya")
{

Jornada jornada = _context.Jornades.SingleOrDefault(j => j.JornadaID == value.Value.JornadaID);

jornada.Descripcio = value.Value.Descripcio;
jornada.DataIniciJornadaUTC = value.Value.DataIniciJornadaUTC;
jornada.DataIniciApostesUTC = value.Value.DataIniciApostesUTC;
jornada.DataFinalitzacioApostesUTC = value.Value.DataFinalitzacioApostesUTC;
jornada.PermesApostar = value.Value.PermesApostar;
jornada.Finalitzada = value.Value.Finalitzada;

_context.SaveChanges();

return Json(value.Value);
}
}
return BadRequest();
} catch(Exception e)
{
throw new Exception(e.InnerException.Message);
}

}

public ActionResult Remove([FromBody]CRUDModel<Jornada> value)
{
try
{
var jornada = _context.Jornades.SingleOrDefault(j => j.JornadaID == int.Parse(value.Key.ToString()));
if (jornada == null)
{
return NotFound();
}

var campionat = _context.Campionats.SingleOrDefault(c => c.CampionatID == jornada.CampionatID);
if (campionat == null)
{
return NotFound();
}
var _up = new Infrastructure.UsuarisPenyaObject(_context, _userManager.GetUserId(HttpContext.User), campionat.PenyaID);

if (_up != null)
{

if (_up.Role() == "AdministradorPenya")
{

_context.Jornades.Remove(jornada);

_context.SaveChanges();

return Json(value);
}
}
return BadRequest();
} catch (Exception e)
{
throw new Exception(e.InnerException.Message);
}
}


2. Screenshot of post sent to server



3. No script error in console

4. Essential studio version

     16.2.0.41


Farveen Sulthana Thameeztheen Basha [Syncfusion]
Replied On December 12, 2018 12:05 PM UTC

Hi Jordi, 

We can reproduce your reported problem from your code example. The reported problem occurs because you have defined primary key column (i.e JornadaID column ) as hidden in template form. So the save action is not working. To avoid the reported issue you should define the primary key column in template form (or) update the random value for primary key column in actionBegin event refer the below code. 


<ej-grid id="FlatGrid" allow-paging="true" datasource="ViewBag.datasource" action-begin="begin" allow-filtering="true"> 
          <e-columns> 
                <e-column field="OrderID" header-text="Order ID" is-primary-key="true"></e-column> 
                               .   .    . 
                
            </e-columns> 
        </ej-grid> 
 
function begin(args) { 
          if (args.requestType == "save" && ej.isNullOrUndefined(args.data.OrderID)){ 
                args.data.OrderID = Math.random(); // Add the random value for primary key column. 
            } 
        } 

Refer to the API link:- 

Please get back to us if you need any further assistance. 
 
Regards, 
Farveen sulthana T 


Jordi
Replied On December 12, 2018 07:26 PM UTC

Hi Farveen,

That was exactly the problem. Issue fixed. Thank you !!

Vignesh Natarajan [Syncfusion]
Replied On December 13, 2018 04:10 AM UTC

Hi Jordi, 

Thanks for the update.  

We are glad to hear that your query has been resolved by our solution. 

Please get back to us if you have further queries. 

Regards, 
Vignesh Natarajan 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon

Live Chat Icon For mobile
Live Chat Icon