locked
Save data on runtime and one button click to save in database RRS feed

  • Question

  • User-2131816816 posted

    Hi,

    I have an application where i need to save some data on runtime and then save it to the database on one click.

    Just an example I have 5 columns in my database. called ID,ParentID,col1,col2,col3,. This is my child table.

    I have a parent table and bind with child table. Child table will have multiple rows of data and all things to be saved in One click on Save data. I will add on my interface with Add row button which save data at runtime. And then will have 1 save button which saves all the data after adding all my child rows and displayed in grid all the data.

    Thanks.

    Monday, October 29, 2018 4:51 PM

All replies

  • User475983607 posted

    Do your have a question?  Are you receiving and error?  Is there anyway you can post your source code?

    Monday, October 29, 2018 5:17 PM
  • User-2131816816 posted

    I m new to MVC and if someone can make a small project for me then that would be easy to understand the code.

    Thanks.

    Monday, October 29, 2018 5:47 PM
  • User753101303 posted

    Hi,

    Start with https://www.c-sharpcorner.com/UploadFile/4b0136/editing-multiple-records-using-model-binding-in-mvc/

    and use view source to see how controls are named. Basically it uses name="[<int>].PropertyName" and when posted you get back an array again. And so based on that it should be relatively easy to add other row(s) using JavaScript so that they are taken as well into account...

    Edit: more likkely a MVC todo list code sample might show this kind of thing. I often prefer to explain how things works and what should be done rather than to provide ready to use code as you likely learn more by doing things yourself (though here and depending on how new you are, it might be needed).

    Edit: a bit old but http://blog.stevensanderson.com/2010/01/28/editing-a-variable-length-list-aspnet-mvc-2-style/ looks quite a good start if you are feel uncomforable with JavaScript. Will have to check but I believe it is no that difficult to do that without the helper.

    Monday, October 29, 2018 6:02 PM
  • User-2131816816 posted

    Can you please make one small project for me as I am new to MVC?

    Thanks.

    Tuesday, October 30, 2018 7:42 PM
  • User1520731567 posted

    Hi hozefa_unwala,

    hozefa_unwala

    Just an example I have 5 columns in my database. called ID,ParentID,col1,col2,col3,. This is my child table.

    I have a parent table and bind with child table. Child table will have multiple rows of data and all things to be saved in One click on Save data. I will add on my interface with Add row button which save data at runtime. And then will have 1 save button which saves all the data after adding all my child rows and displayed in grid all the data.

    According to your descriptions,I think you could make an one to many entity relationship between parent table and child table.

    And then after creating two models,I suggest you could add a scaffolded item to do a CURD project quickly.

    You could follow the steps below:

    Right click on Controllers -> Choose Add -> Choose 'MVC5 Controller with views, using Entity Framework', then Add-> Choose the Model  you want to add CRUD to in 'Model class', then Add -> The controller with CRUD function is created.

    Then the  Index,Details,Edit ..pages will be automatically generated.

    Or you could refer to:

    https://www.codeproject.com/Tips/766214/List-Model-Binding-in-MVC

    Best Regards.

    Yuki Tao

    Wednesday, October 31, 2018 5:59 AM