I'm building an ASP.NET MVC5 application with C# and SQL server/EF6.
I have a table with 50 columns. In the first step of the app, I need to post values of 12 column only to this table. Rest of columns will either stay null, or get filled (through update query in EF6), along the app flow and according to user choices.
How to implement a post request in EF6 without throwing an exception of System.ArgumentNullException: Value cannot be null?
public S_REQUEST Save_S_Without_All_Data(SViewModel vm)
{
var s_request = new S_REQUEST
{
//mapping model properties with viewmodel properties
};
return s_request;
}
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult PostAction(SViewModel vm)
{
switch (selectedStep){
//other cases
case "2":
try {
if (ModelState.IsValid)
{
var s_request = Save_S_Without_All_Data(vm);
db.S_REQUEST.Add(s_request);
//add DELEGATED_EMPLOYEE_ID
var s_request_extra_data = new S_REQUEST
{
DELEGATED_EMPLOYEE_ID = vm.DelegatedTeamMemberId
};
db.S_REQUEST.Add(s_request_extra_data);
db.SaveChanges();
return View("Success");
}
return View(vm);
}
catch
{
ModelState.AddModelError("SaveError", "Unable to save changes.");
}
break;
//other cases
}