Skip to content
Loading
How to save changes to db, using mutliple models in one view?  
  •   
  •                             class="form-group row">  
  •                                 for="Name" class="col-sm-2 col-form-label">Name:  
  •                                 class="col-sm-3 ">  
  •                                     @Html.EditorFor(model => model.RegForm.FirstName, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "Name" } })  
  •                                     @Html.ValidationMessageFor(model => model.RegForm.FirstName, ""new { @class = "text-danger" })  
  •   
  •                                   
  •   
  •                                 class="col-sm-3">  
  •                                     @Html.EditorFor(model => model.RegForm.LastName, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "LastName" } })  
  •                                     @Html.ValidationMessageFor(model => model.RegForm.LastName, ""new { @class = "text-danger" })  
  •                                   
  •                               
  •   
  •                             class="form-group row">  
  •                                 for="Position" class="col-sm-2 col-form-label">Position:  
  •                                 class="col-sm-3">  
  •                                     @Html.EditorFor(model => model.RegForm.Position, new { htmlAttributes = new { @class = "form-control" } })  
  •                                     @Html.ValidationMessageFor(model => model.RegForm.Position, ""new { @class = "text-danger" })  
  •                                   
  •                               
  •   
  •                             class="form-group row">  
  •                                 for="Company" class="col-sm-2 col-form-label">Company:  
  •                                 class="col-md-3">  
  •                                     @Html.EditorFor(model => model.RegForm.Company, new { htmlAttributes = new { @class = "form-control" } })  
  •                                     @Html.ValidationMessageFor(model => model.RegForm.Company, ""new { @class = "text-danger" })  
  •                                   
  •                               
  •   
  •                             class="form-group row">  
  •                                 for="Addresss" class="col-sm-2 col-form-label">Address*  
  •                                 class="col-sm-5">  
  •                                     @Html.EditorFor(model => model.RegForm.StreetAddress, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "Street Address" } })  
  •                                     @Html.ValidationMessageFor(model => model.RegForm.StreetAddress, ""new { @class = "text-danger" })  
  •                                   
  •                               
  •                             class="form-group row">  
  •                                 for="Address" class="col-sm-2 col-form-label">  
  •                                 class="col-sm-5">  
  •                                     @Html.EditorFor(model => model.RegForm.StreetAddress, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "Street Address Line 2" } })  
  •                                     @Html.ValidationMessageFor(model => model.RegForm.StreetAddress, ""new { @class = "text-danger" })  
  •                                   
  •                               
  •                             class="form-group row">  
  •                                 for="City" class="col-sm-2 col-form-label">  
  •                                 class="col-sm-3">  
  •                                     @Html.EditorFor(model => model.RegForm.City, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "City" } })  
  •                                     @Html.ValidationMessageFor(model => model.RegForm.City, ""new { @class = "text-danger" })  
  •                                   
  •                                 for="State/Province" class="col-form-label">  
  •                                 class="col-sm-3">  
  •                                     @Html.EditorFor(model => model.RegForm.StateProvince, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "State/Province" } })  
  •                                     @Html.ValidationMessageFor(model => model.RegForm.StateProvince, ""new { @class = "text-danger" })  
  •                                   
  •   
  •                               
  •                             class="form-group row">  
  •                                 for="ZipCode" class="col-sm-2 col-form-label">  
  •                                 class="col-sm-3">  
  •                                     @Html.EditorFor(model => model.RegForm.ZipCode, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "ZipCode" } })  
  •                                     @Html.ValidationMessageFor(model => model.RegForm.ZipCode, ""new { @class = "text-danger" })  
  •                                   
  •   
  •                                 class="col-sm-3">  
  •                                     @Html.DropDownListFor(m => m.ListCountries.Country, ViewBag.CountryList as SelectList)  
  •                                   
  •                               
  •   
  •                             class="form-group row">  
  •                                 for="Email" class="col-sm-2 col-form-label">Email:  
  •                                 class="col-sm-4">  
  •                                     @Html.EditorFor(model => model.RegForm.Email, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "Email" } })  
  •                                     @Html.ValidationMessageFor(model => model.RegForm.Email, ""new { @class = "text-danger" })  
  •                                   
  •                               
  •   
  •                             class="form-group row">  
  •                                 for="Attendee" class="col-sm-2 col-form-label">Attendee Cell Number*  
  •                                 class="col-sm-3">  
  •                                     @Html.EditorFor(model => model.RegForm.CellNumber, new { htmlAttributes = new { @class = "form-control", autofocus = "autofocus", placeholder = "Cell Number" } })  
  •                                     @Html.ValidationMessageFor(model => model.RegForm.CellNumber)  
  •                                   
  •                               
  •   
  •                             class="form-group row">  
  •                                 for="Verify not a human" class="col-sm-2 col-form-label">Please verify you not a human*  
  •                                 class="col-sm-3">  
  •                                     @using (Html.BeginForm("FormSubmit""GetCapatcha", FormMethod.Post))  
  •                                     {  
  •                                         class="g-recaptcha" data-sitekey="6LcLN6cZAAAAABbgHtWziQB9nsWNXqZcpBnLU6dd">  
  •   
  •                                           
  •                                     }  
  •                                   
  •                               
  •   
  •                             class="form-group row">  
  •                                 class="col-sm-2 col-form-label">Dietary requirements:  
  •                                 class="col-sm-3">  
  •                                     class="form-check">  
  •                                         @Html.CheckBoxFor(m => m.DietMain.None, new { @class = "form-check-input" })  
  •                                         class="form-check-label" for="@Html.IdFor(m => m.DietMain.None)">None  
  •                                       
  •                                     class="form-check">  
  •                                         @Html.CheckBoxFor(m => m.DietMain.Vegetarian, new { @class = "form-check-input" })  
  •                                         class="form-check-label" for="@Html.IdFor(m => m.DietMain.Vegetarian)">Vegetarian  
  •                                       
  •   
  •                                     class="form-check">  
  •                                         @Html.CheckBoxFor(m => m.DietMain.Vegan, new { @class = "form-check-input" })  
  •                                         class="form-check-label" for="@Html.IdFor(m=>m.DietMain.Vegan)">Vegan  
  •                                       
  •   
  •                                     class="form-check">  
  •                                         @Html.CheckBoxFor(m => m.DietMain.Halaal, new { @class = "form-check-input" })  
  •                                         class="form-check-label" for="@Html.IdFor(m=>m.DietMain.Halaal)">Halaal  
  •                                       
  •   
  •                                     class="form-check">  
  •                                         @Html.CheckBoxFor(m => m.DietMain.Other, new { @class = "form-check-input" })  
  •                                         class="form-check-label" for="@Html.IdFor(m=>m.DietMain.Other)">Other  
  •                                       
  •   
  •                                   
  •                               
  •   
  •                           
  •   
  •                         class="form-group">  
  •                             class="col-md-offset-2 col-md-10">  
  •                                 "submit" value="Submit" class="btn btn-primary" />  
  •   
  •                               
  •                           
  •   
  •                     }  
  •                     
      
  •                         @Html.ActionLink("Back to list""SaveRegForm")  
  •                       
  •                   
  •  
  • Jignesh Kumar
    Hi,
     
    Please use this model in your view and access via properties,
    1. @using RegViewAndRoleViewModel    
    2. @model RegViewAndRoleViewModel    
    3. @{    
    4.     ViewBag.Title = "SubmitRegDetails";    
    5. }   
     For more reference you can use this link which will help you,
    https://www.c-sharpcorner.com/article/asp-net-mvc5-multiple-view-models-in-single-view/ 
  • Jenith Thakkar
    Hi

    In view 
    Change this thing

    @using eNtsaRegistrationTraining.Models.RegViewAndRoleViewModel