Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6683183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:47:29+00:00 2026-05-26T04:47:29+00:00

Question: When the user clicks submit what is the best strategy to insert the

  • 0

Question: When the user clicks submit what is the best strategy to insert the data into the correct tables?Should I instantiate 3 viewmodels in the httppost and use the Myform atributes to populate my 3 view models 1.mvr, 2.MvrMedication 3.AdminRoute Then save record for each?

Suppose that someone goes to a form that has data from all 3 view models below

 1. MVR class, 
 2. MvrMedication
 3. AdminRoute

So my viewmodel
looks like

public class MyForm
{
   public virtual Mvr Mvr{get;set;}
   public virtual MvrMedication MvrMedication{get;set;}
   public virtual AdminRoute AdminRoute{get;set;}
}

Then
In the view Editor for all my atributes.
When the user clicks submit what is the best strategy to insert the data into the correct tables?

Below is some code just for reference

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
//Please use: http://blogs.msdn.com/b/efdesign/archive/2010/06/01/conventions-for-code-first.aspx

namespace MVR.Models.Tables
{
    public class Mvr
    {
        [Key]
        public virtual int MvrId { get; set; }
        public virtual ICollection<MvrMedication> MvrMedicationId { get; set; }

        public virtual DateTime DateOfReport { get; set; }
        public virtual DateTime DateOfVariance { get; set; }
        public virtual String   IndividualFirstHospitalNumber { get; set; }
        public virtual String   MallUnit { get; set; }
        public virtual Boolean  PhysicianNotified { get; set; }
        public virtual DateTime PhysicianDateNotified { get; set; }
        public virtual Boolean   PharmacistNotified { get; set; }
        public virtual DateTime PharmacistDateNotified { get; set; }
        public virtual DateTime PharmacistDateOfNotification { get; set; }
        public virtual Boolean  InitialSignature { get; set; }
        public virtual String   VarianceDescription { get; set; }

    }
}







using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace MVR.Models.Tables
{
    public class AdminRoute
    {
        [Key]
        public virtual int AdminRouteId { get; set; }
        public virtual MvrMedication MvrMedicationId { get; set; }
        public virtual string RouteName { get; set; }
    }

    }






    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.ComponentModel.DataAnnotations;
    namespace MVR.Models.Tables
    {
        public class MvrMedication
        {
            [Key]
            public virtual int MvrMedicationId{ get; set; }
            public virtual ICollection<AdminRoute> AdminRouteId { get; set; }

            public virtual string MvrMedicationName { get; set; }

        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:47:29+00:00Added an answer on May 26, 2026 at 4:47 am

    Your view model looks fine, but I would recommend creating view models for the Mvr, MvrMedicine and AdminRoute classes to be more user-friendly. Usually, you’re not supposed to see Id’s in the view.

    On your view side, just use the @Html.EditorFor for the inputs on the form and submit it to an [HttpPost] method in the controller

    @model MvcProject.Models.MyForm
    
    @using (Html.BeginForm()) {
        <fieldset>
            <legend>Mvr</legend>
            @Html.EditorFor(m => m.Mvr)
        </fieldset>
    
        <fieldset>
            <legend>MvrMedication</legend>
            @Html.EditorFor(m => m.MvrMedication)
        </fieldset>
    
        <fieldset>
            <legend>AdminRoute</legend>
            @Html.EditorFor(m => m.AdminRoute)
        </fieldset>
    
        <p>
            <input type="submit" value="Save" />
        </p>
    }
    

    The default @Html.EditorFor() is going to generate the default inputs for every property in the model. You can create your own custom editor templates for each view model or just define each input in the form, but editor templates are cleaner and reusable.

    This is a good tutorial for editor templates. It’s for MVC2 but the concepts are the same.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When a user enters their info into the sign-up page and clicks submit, usernameCheck()
My question is about passing data from kernel to a user space program. I
How do I make don't do anything if a user clicks submit and he
I want to have an ajaxed form and when a user clicks submit it
I am having an ASP.net Membership I need to verify the User Question and
This came up when answering another user's question (TheSoftwareJedi)... Given the following table: ROW_PRIORITY
Question 1 - I'm wanting to give the user the ability to reset their
Question Rewritten: HOMEDIR=ftpuser REMOTEIP=1.1.1.1 MYSQLPASS=password Q1=DROP USER $HOMEDIR_shop; Q2=DROP DATABASE $HOMEDIR_shop; Q3=CREATE DATABASE IF
User kokos answered the wonderful Hidden Features of C# question by mentioning the using
This is a question brought up in a local user group mailing list at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.