I have an application which I created using MVC3 and Custom SQL Database with 3 tables:
mm_Table1
, mm_Table2
, mm_Jobs
I built out the MVC app with a JobsController
and have the respective Views
folder with Create.cshtml
, Delete.cshtml
, Details.cshtml
, Edit.cshtml
and Index.cshtml
I want to associate mm_Profile
with a User.
After integrating the ASPNET_MEMBERSHIP
Tables into my custom database, I added a UserId
column of Type uniqueidentifier
to mm_Jobs
and created the proper foreign key relationship to aspnet_Users
table (FK_Jobs_aspnet_Users
)
I did so and now when I fill out my Jobs form (located in Jobs -> Create.cshtml
) and press the submit button I get the following error :
Cannot insert the value NULL into column 'UserId', table 'MovinMyStuff.dbo.Moves'; column does not allow nulls. INSERT fails. The statement has been terminated
The line of code in my JobsController in my Create()
method:
Line: 52 db.SaveChanges();
How do I update my Create()
to save change and associate the User with the Job, thus pushing the UserId
into the UserId
column in the Jobs
table? The full create method is given below:
[HttpPost]
public ActionResult Create(Job job)
{
if (ModelState.IsValid)
{
db.Moves.Add(job);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(job);
}
I figured this one out. I had an extra _Layout file in my Shared Folder within my Area. Apparantly, even upon hiding it the compiler will see this file.