c# - Convert "null" strings to a NULL Guid

c# - Convert "null" strings to a NULL Guid

guidolsguidols Posts: 36Questions: 14Answers: 1
edited April 2022 in Editor

based on this discussion, I updated the editor.chosen.js script in order to allow empty selections (i.e., the user can now deselect a field).

In this case, Status is a table related to my model and I get the following situation in the editor:

The resulting select is (as per chosen documentation), something like:

<option value=""></option>
<option value="1">S1</option>
<option value="2">S2</option>

and this allows the user to use the chosen single deselect feature.

The problem is server side: I didn't find any code to convert an empty string (or any string) to a "NULL Guid*, in order to set the related Guid to NULL.

For example this code:

editor.PreEdit += (sender, e) =>
  // if the user has deselected the entry
  if ((string)((System.Collections.Generic.Dictionary<string, object>)e.Values["Main"])["Status_Id"] == "")
    // the entry should be set to NULL

Is resulting in the following query:

UPDATE [Main] SET [Status_Id] = @Status_Id WHERE [Main].[Id] = @where_0

The problem is that:

@Status_Id = "null"

So @Status_Id interpreted as string.

Is there any possibility to tell the editor, server side, that I want to convert an empty string (or any string) to NULL, and not to "NULL"?

This question has an accepted answers - jump to answer


Sign In or Register to comment.