Hi bistgeneral,
Refer below code.
Model
public class ProductTypeViewModel
{
public ProductInfo ProductModel { get; set; }
public ProductType TypeModel { get; set; }
}
public class ProductType
{
public int TypeID { get; set; }
public string TypeName { get; set; }
}
public class ProductInfo
{
public string ProName { get; set; }
public int ProID { get; set; }
}
Controller
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
ProductTypeViewModel productViewModel = new ProductTypeViewModel();
return View(productViewModel);
}
[HttpPost]
public ActionResult Index(ProductTypeViewModel productViewModel)
{
ProductType type = productViewModel.TypeModel;
//Insert type.
ProductInfo infor = productViewModel.ProductModel;
//Insert the Product.
return View(productViewModel);
}
}
View
@model Multiple_Table_Insert_ViewModel.Models.ProductTypeViewModel
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
</head>
<body>
@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
<div class="form-horizontal">
<div class="form-group">
@Html.LabelFor(model => model.ProductModel.ProID, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBoxFor(model => model.ProductModel.ProID, "", new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.ProductModel.ProName, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBoxFor(model => model.ProductModel.ProName, "", new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.TypeModel.TypeID, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBoxFor(model => model.TypeModel.TypeID, "", new { @class = "form-control" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.TypeModel.TypeName, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBoxFor(model => model.TypeModel.TypeName, "", new { @class = "form-control" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Insert" class="btn btn-default" />
</div>
</div>
</div>
}
</body>
</html>
Screenshot