Please leave reading the codings part. I mentioned my issue in last. Why i include my DB and Codings means suppose if you didn't understand my issue you can refer this (i.e) what i did from the Starting Itself.
In my project i have Customer Master. It contain 16 fields like
1) Customer ID2) Customer Name 3) Alias 4) Customer Type 5) Street 6) Location 7) Area 8) City 9) Stat 10) Country 11 Tin No 12 Cst No 13 Service Tax No 14 Excise Reg No 15 Pan No 16) Cin No
Customer CustomerID Primary key Uniqueidentifier not null, Display Name Varchar(100) null, Print Name Varchar(100) null, CustomerType ID Uniqueidentifier null.
Customer Address CustomerAddressID Primary key Uniqueidentifier not null, CustomerID Uniqueidentifier null, AddressID Uniqueidentifier null.
Address AddressID Primary key Uniqueidentifier not null,AddressTypeID Uniqueidentifier null, DisplayName Varchar(100) null, SalutationID Uniqueidentifier null, PrintName Varchar(100) null, SimpleMode bit null, DetailMode bit null, Street Varchar(100) null, Location Varchar(100) null, Place Varchar(100) null, AreadID Uniqueidentifier null, Pincode Varchar(100) null.
DisplayName Varchar(100) null, PrintName Varchar(100) null, CityID Uniqueidentifier null.
SalutationID Primary key Uniqueidentifier not null, DisplayName Varchar(100) null, PrintName Varchar(100) null
City CityID Primary key Uniqueidentifier not null, DisplayName Varchar(100) null, PrintName Varchar(100) null , StateID Uniqueidentifier null.
StateId Primary key Uniqueidentifier not null, DisplayName Varchar(100) null , PrintName Varchar(100) null , CountryID Uniqueidentifier null.
Country CountryID Primary key Uniqueidentifier not null, DisplayName Varchar(100) null , PrintName Varchar(100) null.
CustomerTaxInfo
CustomerTaxInfoID Primary key Uniqueidentifier not null,
CustomerID Uniqueidentifier null, TaxInfoReference Varchar(100) null , TaxInfoID Uniqueidentifier null,
Taxfield TaxFieldID PrimaryKey Uniqueidentifier not null, DisplayName Varchar(100) null , PrintName Varchar(100) null.
TaxInfo
TaxInfoID PrimaryKey Uniqueidentifier not null, DisplayName Varchar(100) null , PrintName Varchar(100) null.
TaxInfoTaxField
TaxInfoTaxFieldID PrimaryKey Uniqueidentifier not null, TaxInfoID Uniqueidentifier null,, TaxFieldID Uniqueidentifier null, FieldValue big int,
And My Controller
using System;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Sample_Customer.Models;
namespace Sample_Customer.Controllers
{
public class CustomerController : Controller
VisitorsEntities1 db = new VisitorsEntities1();
//
// GET: /Customer/
public ActionResult Index()
return View();
}
public ActionResult Create()
ViewBag.Country = new SelectList(db.Country, "CountryID", "DisplayName","PrintName");
ViewBag.State = new SelectList(db.State, "StateID", "DisplayName", "PrintName");
ViewBag.City = new SelectList(db.City, "CityID", "DisplayName", "PrintName");
ViewBag.Area = new SelectList(db.Area, "AreaID", "DisplayName", "PrintName");
[HttpPost
public ActionResult Create(CustomerViewModel viewmodel) {
var Customerobj = new Customer()
CustomerID= Guid .NewGuid (),
DisplayName = viewmodel.CustomerName,
PrintName = viewmodel .CustomerName,
CustomerType =viewmodel.CustomerTypeID,
};
var CustomerTypeobj = new CustomerType()
CustomerTypeID= Guid.NewGuid(),
DisplayName = viewmodel.CustomerType,
PrintName= viewmodel.CustomerType
var CustomerAddressobj = new CustomerAddress()
CustomerAddressID= Guid.NewGuid(),
CustomerID= viewmodel.CustomerID,
AddressID= viewmodel.AddressID
var Addressobj = new Address()
AddressID = Guid.NewGuid(),
AddressTypeID = viewmodel.AddressTypeID,
DisplayName= viewmodel.CustomerName,
Salutation= viewmodel.Alias,
PrintName= viewmodel.CustomerName,
Street=viewmodel.Street,
Location= viewmodel.Location,
Place= viewmodel.Place,
Area = viewmodel.AreaID,
PinCode= viewmodel.PinCode
while Saving the data in Database using Code First approach is working fine upto Address.That is It saving the data up to Address details in DB is working Fine. But I got a problem while Saving the Tax details.In my view I have Six Fields like TinNo , CstNo, PanNo, ExciseRegNo, ServiceTxNo, CinNo.Each one have Default value which is saved in TaxField Table.
Eg TinNo = FD713788-B5AE-49FF-8B2C-F311B9CB0CC4
CstNo = 64B512E7-46AE-4989-A049-A446118099C4
CinNo =59A2449A-C5C6-45B5-AA00-F535D83AD48B
Same as like that other field PanNo, ExciseRegNo, ServiceTxNo contain Default Value .
Suppose now I am going to save one customer Details in CustomerMaster view and enter the TinNo ,CstNo, PanNo, ExciseRegNo, ServiceTxNo, CinNo, means it have to save the values(Which is entered in the Field of TinNo in the View) in FieldValue and their ID ( eg TinNo = FD713788-B5AE-49FF-8B2C-F311B9CB0CC4) in TaxFieldID of TaxInfoTaxField Table.That is I need to save those six Field in same column not in same row and same cell. Suppose if I enter the TinNo means it have to save the value in FieldValue and ID in TaxFieldID. Then I enter the CstNo it will automatically go and create the new row and have to save the Value and ID in the FieldValue and TaxFieldID. So for each Customer it will create 6 rows automatically while Saving TaxDetails. How to do this MVC4 ?