Click here to Skip to main content
14,454,989 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi, guys. I have a question related to ASP.Net MVC. I created a project with individual user accounts. And now I've created a model "Room".
<pre lang="c#">public class Room
    {
        public int RoomId { get; set; }
        public string RoomName { get; set; }

        public string OwnerId { get;set }
        public virtual ApplicationUser Owner { get; set; }
    }


And I added
public DBSet<Room> Rooms{get;set;}

And also I created a RoomController which has an ActionResult Create.
private ApplicationDbContext db = new ApplicationDbContext();
        // POST: Room/Create
        [HttpPost]
        public ActionResult Create(Room room)
        {
            try
            {
                db.Rooms.Add(room);
                db.SaveChanges();
                // TODO: Add insert logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }


I'm starting to learn ASP.Net just few weeks. And I've tried so many ways to solve this problem. Also

What I have tried:

Also I've tried to do some operations in HomeController. But it failed too. In my tables of Room there is no OwnerId. How can I connect this model with AspNetUsers?
Posted
Updated 14-Feb-20 2:50am
v2
Comments
phil.o 14-Feb-20 7:45am
   
You did not describe the problem.
Member 14726247 14-Feb-20 7:49am
   
I edited my text.Can you look one more time?
phil.o 14-Feb-20 7:55am
   
It is still impossible to tell where is the issue since we do not have the relevant code.
Have you tried debugging?
Member 14726247 14-Feb-20 7:56am
   
yes.but Create button doesn't work
Member 14726247 14-Feb-20 7:57am
   
so I don't know where is the problem
phil.o 14-Feb-20 8:00am
   
Only you can find out the issue. And you have a tool which is meant for that: debugging. Have you tried? Do you need help on how to debug an ASP.NET project?
Member 14726247 14-Feb-20 8:06am
   
i just tried debugging. and it says that "db.SaveChanges()" is not used. Because OwnerId and Owner have a null value
phil.o 14-Feb-20 8:11am
   
ASP.NET - Debugging[^] will introduce you to the concept of debugging.

There are a lot of other sources, though. Your favourite search engine will give you plenty of links about it.
Put a breakpoint on the line where you are assigning the owner; and follow the values of your variables from there.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100