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 : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

MVC 6 Can't Save New Row to Database

Thread ID:

Created:

Updated:

Platform:

Replies:

123581 Apr 1,2016 04:35 AM UTC Apr 5,2016 09:24 AM UTC ASP.NET MVC 4
loading
Tags: Grid
Cody S
Asked On April 1, 2016 04:35 AM UTC

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

Cody S
Replied On April 2, 2016 09:48 PM UTC

Any ideas what I might be missing?

Prasanna Kumar Viswanathan [Syncfusion]
Replied On 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


Cody S
Replied On 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

Gowthami V [Syncfusion]
Replied On 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


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.

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

;