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

Adding record in edit mode in grid does not work

Thread ID:

Created:

Updated:

Platform:

Replies:

146427 Aug 2,2019 08:35 PM UTC Aug 7,2019 12:43 PM UTC Blazor 4
loading
Tags: Grid
ebi torabi
Asked On August 2, 2019 08:35 PM UTC

@page "/AllergyCategoriesPage"
@inject HttpClient http
<EjsGrid id="Grid" @ref="@grid" TValue="AllergyCategories" EnableRtl="true" AllowFiltering="true" AllowResizing="true" AllowSorting="true" AllowTextWrap="true" ShowColumnChooser="true" ShowColumnMenu="true" GridLines="@GridLine.Both" Height="100%" AllowGrouping="true" AllowPaging="true" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Cancel", "Update" })">
    <EjsDataManager Adaptor="Adaptors.WebApiAdaptor" Url="api/AllergyCategories" CrossDomain="true"></EjsDataManager>
    <GridFilterSettings Type="@Syncfusion.EJ2.Blazor.Grids.FilterType.Menu"></GridFilterSettings>
    <EjsPager PageSize="12"></EjsPager>
    <GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" Mode="EditMode.Dialog"></GridEditSettings>
    <GridColumns>
        <GridColumn Field=@nameof(AllergyCategories.AllergyCategoryId) HeaderText="AllergyId" TextAlign="@TextAlign.Center" IsPrimaryKey="true" IsIdentity="true"></GridColumn>
        <GridColumn Field=@nameof(AllergyCategories.AllergyCategoryName) HeaderText="AllergyName" TextAlign="@TextAlign.Center" ValidationRules="@(new { required= true })"></GridColumn>

    </GridColumns>
</EjsGrid>
@code{
    EjsGrid<AllergyCategories> grid;
}

namespace Newsha.Server.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class AllergyCategoriesController : ControllerBase
    {
       private readonly AllergyCategoriesDataAccessLayer db = new AllergyCategoriesDataAccessLayer();
        [HttpGet]

        public object Get()
        {
            IEnumerable<AllergyCategories> data = db.GetAll();
            var count = data.Count();
            var queryString = Request.Query;
            if (queryString.Keys.Contains("$inlinecount"))
            {
                StringValues Skip;
                StringValues Take;
                int skip = (queryString.TryGetValue("$skip", out Skip)) ? Convert.ToInt32(Skip[0]) : 0;
                int top = (queryString.TryGetValue("$top", out Take)) ? Convert.ToInt32(Take[0]) : data.Count();
                return new { Items = data.Skip(skip).Take(top), Count = count };
            }
            else
            {
                return  data;
            }
        }
        // GET: api/Default/5
        [HttpGet("{id}")]
        public AllergyCategories Get(object id)
        {
            return  db.FindById(id);
        }
        // POST: api/Default
        [HttpPost]
        [HttpGet("[action]")]
        public object GetNameId()
        {
            return db.GetNameId();
        }
        public void Post([FromBody] AllergyCategories entity)
        {
            if (ModelState.IsValid)
            {
                 db.Add (entity);
               
            }
        }
        // PUT: api/Default/5
        [HttpPut]
        public void  Put([FromBody] AllergyCategories entity)
        {
            if (ModelState.IsValid)
            {
                db.Update(entity);  
            }
        }
        // DELETE: api/ApiWithActions/5
        [HttpDelete("{id}")]
        public void DeleteById(int id)
        {
            if (ModelState.IsValid)
            {
                db.DeleteById(id);
            }
        }
    }

}



 public void Add(AllergyCategories entity)
        {
            try
            {

                 _UW.AllergyCategories.Add(entity);
                 _UW.Commit();

            }
            catch
            {
                throw;
            }
        }






Attachment: add2_5d4fbe77.rar

Vignesh Natarajan [Syncfusion]
Replied On August 5, 2019 10:19 AM UTC

Hi Ebi Torabi,  

Thanks for contacting Syncfusion forums.  

Query: “Adding a record in edit mode does not work” 
 
As per your code example we have prepared a sample with entity frame work and we are not able to reproduce the reported issue at our end. We are able to add the record without any error.  

For your convenience we have prepared a sample which can be downloaded from below  

From the video demonstration and code example we have found that you have defined the Primarykey column as IsIdentity. We suspect that value of PrimaryKey column is not properly assigned while adding a record. 

While adding a record, the value of PrimaryKey column must be sent to server to insert the record into database properly. But in your code example IsIdentity property also enabled for that PrimaryKey column, then it will prevent the user to insert a value to that column. In this case, IsIdentity property must be enabled in database also for that corresponding column to auto Increment the column value or its value must be incremented in server before inserting it into database.    

Refer our UG documentation Notes section for your reference 


If you are still facing the issue, kindly share the following details. 

  1. Ensure that you have enabled IsIdentity property to the Auto Increment column in database.
  2. Or Provide the unique value to primaryKey column while inserting.
  3. Share the screenshot of script error in console or Network tab with failure details.
  4. Also share the Network tab of post sent to server while inserting a record or Keep a break point in server while inserting a record and share the argument received
  5. If possible try to reproduce the reported issue in provided sample.

Requested details will be helpful for us to validate the reported issue at our end and provide you the solution as soon as possible.  

Regards, 
Vignesh Natarajan. 


ebi torabi
Replied On August 5, 2019 12:02 PM UTC

Hi Vignesh Natarajan
Please this sample in vs preview 7(in this does not work);
in this doesn call controller.
meanwhile AllergyCategoryId  in my database is  auto Incremental But I need to define the AllergyCategoryId as  follows to work :



using System;
using System.Collections.Generic;

namespace Newsha.Shared.Models
{
    public partial class AllergyCategories
    {
        public AllergyCategories()
        {
            Allergies = new HashSet<Allergies>();
        }

        public int? AllergyCategoryId { get; set; }
        public string AllergyCategoryName { get; set; }

        public virtual ICollection<Allergies> Allergies { get; set; }
    }
}

Vignesh Natarajan [Syncfusion]
Replied On August 6, 2019 06:36 AM UTC

Hi Ebi Torabi, 

Query: “Please this sample in vs preview 7(in this does not work); 

As per your suggestion we have ensured the reported issue by upgrading the sample to .NET Core 3.0 Preview 7 and we are not able to reproduce it at our end. We have attached the upgraded sample below for your reference 


After referring the sample, if you are still facing the issue. Kindly share the following details to validated the reported issue at our end.   
  1. Share the screenshot of script error in console or Network tab with failure details. (if any)
  2. Share the screenshot of Network tab when post is sent to server while inserting a record or Keep a break point in server while inserting a record and share the argument received.
  3. If possible try to reproduce the reported issue in provided sample  or share the issue reproducible sample.
  4. Share your Syncfusion Nuget package version.
  5. Also ensure that you have referred the latest version of Nuget (17.2.0.40-Beta), Script (17.2.40) and css files in the project.
Regards, 
Vignesh Natarajan. 


ebi torabi
Replied On August 7, 2019 12:43 PM UTC

Hi Vignesh Natarajan. Thank you very much for your reply.

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