public static async Task AddCustomerAsync(string firstName, string lastName, string address)
{
using (var context = new MyContext())
{
var customer = new Customer
{
FirstName = firstName,
LastName = lastName,
Address = address
};
context.Customers.Add(customer);
await context.SaveChangesAsync();
}
According to your code,I suggest you could move to
ASP.NET Core to get more help.
Best Regards.
Yuki Tao
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
131 Points
321 Posts
Post & Save multi Item to table using ef 2.1
Feb 11, 2019 12:42 PM|john_mm|LINK
Hello ,
im trying to select item( using checkbox) from a list and post
value (EG-Id) to controller
My end results should be for each id (& more data from the list ) will have its own row in the Db table I would like to send the data .
1. I don't know how to post this list to controller from view
2. I don't know how to handle this data on the controller side
Thanks
All-Star
193986 Points
28020 Posts
Moderator
Re: Post & Save multi Item to table using ef 2.1
Feb 11, 2019 02:04 PM|Mikesdotnetting|LINK
Your action needs to take a collection type as a parameter, such as a List<int> or int[]:
Contributor
3710 Points
1431 Posts
Re: Post & Save multi Item to table using ef 2.1
Feb 12, 2019 06:29 AM|Yuki Tao|LINK
Hi john_mm,
According to your code,I suggest you need to avoid the same name,because controller get values from html tags' name.
So,you could set variable in name,for example:
You could refer to this link:
https://entityframeworkcore.com/saving-data-savechangesasync
for example:
According to your code,I suggest you could move to ASP.NET Core to get more help.
Best Regards.
Yuki Tao
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
131 Points
321 Posts
Re: Post & Save multi Item to table using ef 2.1
Feb 12, 2019 02:52 PM|john_mm|LINK
Thanks Mike