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. Image for the cookie policy date

MVC 6 Can't Save New Row to Database

I'm having issues using MVC6, Entity Framework 7, and the latest SyncFusion files. When I insert a new row, I hit the breakpoint in my insert method in the controller. In the web, the new row data is getting passed as JSON, but when it hits my insert method, the parameter is empty instead of containing the new row info JSON. Any ideas?

View:
        @{Html.EJ().Grid<ToDo>("ToDoItemGrid")
                .AllowPaging()
                .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing().EditMode(EditMode.Dialog).ShowDeleteConfirmDialog(); })
                .ShowColumnChooser()
                .EnableAltRow()
                .ToolbarSettings(toolbar =>
                {
                    toolbar.ShowToolbar().ToolbarItems(items =>
                    {
                        items.AddTool(ToolBarItems.Add);
                        items.AddTool(ToolBarItems.Edit);
                        items.AddTool(ToolBarItems.Delete);
                        items.AddTool(ToolBarItems.Update);
                        items.AddTool(ToolBarItems.Cancel);
                        items.AddTool(ToolBarItems.Search);
                        items.AddTool(ToolBarItems.PrintGrid);
                    });

                })
                .Columns(col =>
                {
                    col.Field("ToDoItem").HeaderText("To Do").TextAlign(TextAlign.Left).Width(100).Add();
                    col.Field("DueDate").HeaderText("Due Date").Format("{0:MM/dd/yyyy}").TextAlign(TextAlign.Left).Width(25).EditType(EditingType.Datepicker).Add();
                    col.Field("IsImportant").HeaderText("Important").TextAlign(TextAlign.Left).Width(25).EditType(EditingType.Boolean).Add();

                })
                .Datasource(ds => ds.Json(ViewBag.Model).InsertURL(@insertUrl).RemoveURL(@removeUrl).Adaptor(AdaptorType.RemoteSaveAdaptor))
                .Render();
            }

Controller:
        public ActionResult Insert(ToDo value)
        {
            if (ModelState.IsValid)
            {
                _repository.AddTodo(value);
            }

            var toDoItems = _repository.GetAllItems();

            return Json(toDoItems);
        }

Thanks!
Cody

Attachment: NewRowDataImages_e8388a16.zip

4 Replies

CS Cody S April 2, 2016 09:48 PM UTC

Any ideas what I might be missing?


PK Prasanna Kumar Viswanathan Syncfusion Team April 4, 2016 01:15 PM UTC

Hi Cody,

Thanks for contacting Syncfusion support.

To get the row information in the parameter, we suggest you to mention the [FromBody] attribute in your controller action.

Please find the code example:

public IActionResult NormalUpdate([FromBody]Orders value)

{

   -----------------------
}


For more information, please refer the below links:

https://github.com/aspnet/Home/issues/1075

http://stackoverflow.com/questions/34080796/model-binding-issue-with-asp-net5-mvc6

If you still face the issue, please get back to us.

Regards,
Prasanna Kumar N.S.V



CS Cody S April 5, 2016 12:12 AM UTC

Unfortunately with [FromBody], the parameter is still null. The only way so far I've been able to get some sort of result is to use  public ActionResult Insert([FromBody]dynamic value), but I don't think using "dynamic" instead of my model is ideal. Any other suggestions?

I'm stuck as to why the json is getting posted in the web, but null in the controller when passed in as a parameter.

Thanks!
Cody


GV Gowthami V Syncfusion Team April 5, 2016 09:24 AM UTC

Hi Cody,

We considered this “Need Generic class to perform the CRUD action” as an usability issue request and a support incident has been created under your account to track the status of this requirement. Please log on to our support website to check for further updates.


https://www.syncfusion.com/account/login?ReturnUrl=/support/directtrac/incidents


Regards,

Gowthami V


Loader.
Up arrow icon