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.
Unfortunately, activation email could not send to your email. Please try again.

Null value for empty entries in DropDown

Thread ID:





123326 Mar 8,2016 10:11 AM Mar 9,2016 11:05 PM ASP.NET MVC 3
Tags: Grid
Omar Muscatello
Asked On March 8, 2016 10:11 AM

Hello Syncfusion Team,
I'm working with the Grid control.

The grid show a nested entity throught:

col.Field(x => x.Categoria.Id).HeaderText("Categoria")

I want to allow the user to set an empty value for this field. In the controller I added:

        public ActionResult Index()
            var categorie = new DataDbContext().Categorie.ToList();
            categorie.Add(new Categoria()); // Empty entry, Id = 0

            ViewBag.Categorie = categorie;
            return View();

In this way, it shows the empty entry.

In the controller, to save the changes I use:

        public JsonResult Modifica(PazienteViewModel.Index value)
            using (DataDbContext db = new DataDbContext(false))
                Paziente mPaziente = db.Pazienti.Find(value.Id);


                mPaziente.IdCategoria = value.Categoria?.Id == 0 ? null : value.Categoria?.Id; // When the user selects the empty entry, value.Categoria.Id = 0, so I have to check if 0 and replace with null. 


                return Json(true);

Is there any alternative for the code highlighted in yellow?

Balaji Marimuthu [Syncfusion]
Replied On March 9, 2016 09:16 AM

Hi Omar,

Thanks for contacting Syncfusion support.

You have processed the correct way and it’s the best approach. So we suggest you to the same, and get back to us if you need any further assistance.

Balaji Marimuthu

Omar Muscatello
Replied On March 9, 2016 12:22 PM

Ok, thank you Balaji Marimuthu.

Balaji Marimuthu [Syncfusion]
Replied On March 9, 2016 11:05 PM

Hi Omar,

Thanks for the update.

Please get back to us if you need any further assistance.

Balaji Marimuthu


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.

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.