Hi team
I have multiple models in my View, the issue my form does not save to my db. I have before when used one it was saving well all changes to my db. Kindly please help me to improve my logic better and stuck.
-
-
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult SubmitRegDetails([Bind(Include= "Id, Title, FirstName, LastName, Position, Company, StreetAddress, StreetAddressLine, City, StateProvince, ZipCode,Country,Email, CellNumber, DietaryRequirement")]TrainingRegForm eNtsaTraining)
- {
- this.ViewBag.SubmitRegDetails = this.SaveRegForm();
-
- if(ModelState.IsValid)
- {
- eNtsaTraining.Id = Guid.NewGuid();
- db.TrainingRegs.Add(eNtsaTraining);
- db.SaveChanges();
- return RedirectToAction("SaveRegForm");
- }
-
-
- if(ModelState.IsValid)
- {
- return RedirectToAction("SaveRegForm");
- }
- return View(eNtsaTraining);
- }
-
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Data.Entity;
- using eNtsaRegistrationTraining.Models;
-
- namespace eNtsaRegistrationTraining.DAL
- {
- public class eNtsaRegistration:DbContext
- {
-
- public eNtsaRegistration() : base("eNtsaRegistration")
- {
- } public DbSet<TrainingRegForm> TrainingRegs { get; set; }
-
- protected override void OnModelCreating(DbModelBuilder modelBuilder)
- {
- base.OnModelCreating(modelBuilder);
- }
- }
- }
-
-
- namespace eNtsaRegistrationTraining.Models
- {
- public class TrainingRegForm
- {
- [Key]
- public Guid? Id { get; set; }
- public string Title { get; set; }
- public string FirstName { get; set; }
- public string LastName { get; set; }
- public string Position { get; set; }
- public string Company { get; set; }
-
- public string StreetAddress { get; set; }
-
- public string StreetAddressLine { get; set; }
-
- public string City { get; set; }
- public string StateProvince { get; set; }
-
- public int ZipCode { get; set; }
-
- public string Country { get; set; }
-
- public string Email { get; set; }
-
- [Required(ErrorMessage = "This field is required")]
- [DataType(DataType.PhoneNumber)]
- public string CellNumber { get; set; }
- public string DietaryRequirement { get; set; }
- }
-
-
- public class RegViewAndRoleViewModel
- {
- public DietViewModel DietMain { get; set; }
-
- public TrainingRegForm RegForm { get; set; }
-
- public DropDownViewModel ListCountries { get; set; }
- public RegistrationTrainingForm HomeModel { get; set; }
- public RoleViewModel RoleViewModelData { get; set; }
-
-
- }
-
- @using eNtsaRegistrationTraining.Models
- @model RegViewAndRoleViewModel
- @{
- ViewBag.Title = "SubmitRegDetails";
- }
Its not sending to db, but if i am using one model(TbRegistrationForm only) it does save straight to my DB with all form fields.