Solved

simple "SAVE" -- C# ASP.net MVC4 ?

Posted on 2013-11-06
2
549 Views
Last Modified: 2013-11-06
Below runs, but does not insert the two new records.

How can I fix ?

Steps
 1. go to http://localhost:63802/C21/MAINT_WORK_REQ/test1
 2. below code runs
 3. refresh database
 4. below new records do NOT appear

----------------------------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MWR.Models;

namespace MWR.Areas.C21.Controllers
{

    public class MAINT_WORK_REQController : Controller
    {
        private MVC_testEntities db = new MVC_testEntities();

        public ActionResult test1()
        {
            //create First Record
            MAINT_WORK_REQ mwr1 = new MAINT_WORK_REQ();
            mwr1.ProgramID = "1";
            mwr1.ProjectID = "1";
            mwr1.CreatedBy = "1";
            mwr1.LastModifiedBy = "1";
            mwr1.HSS_FWD = true;
            mwr1.HSS_INB = false;
            mwr1.HSS_OUTB = true;
            mwr1.BODYSTA_FWD = true;
            mwr1.BODYSTA_BOT = true;
            mwr1.BODYSTA_TOP = true;
            mwr1.EngineerRequired = true;

            //create Second Record
            MAINT_WORK_REQ mwr2 = new MAINT_WORK_REQ();
            mwr2.ProgramID = "1";
            mwr2.ProjectID = "1";
            mwr2.CreatedBy = "1";
            mwr2.LastModifiedBy = "1";
            mwr2.HSS_FWD = true;
            mwr2.HSS_INB = false;
            mwr2.HSS_OUTB = true;
            mwr2.BODYSTA_FWD = true;
            mwr2.BODYSTA_BOT = true;
            mwr2.BODYSTA_TOP = true;
            mwr2.EngineerRequired = true;

            //add both records
            db.SaveChanges();

            return View(db.MAINT_WORK_REQ.ToList());
        }
0
Comment
Question by:finance_teacher
2 Comments
 
LVL 75

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 39627534
Is there any sort of Add* method on your MVC_testEntities class?
0
 

Author Comment

by:finance_teacher
ID: 39627768
Below works

        public ActionResult test1()
        {
            //create First Record
            MAINT_WORK_REQ mwr1 = new MAINT_WORK_REQ();
            mwr1.ProgramID = "1";
            mwr1.ProjectID = "1";
            mwr1.CreatedBy = "1";
            mwr1.LastModifiedBy = "1";
            mwr1.HSS_FWD = true;
            mwr1.HSS_INB = false;
            mwr1.HSS_OUTB = true;
            mwr1.BODYSTA_FWD = true;
            mwr1.BODYSTA_BOT = true;
            mwr1.BODYSTA_TOP = true;
            mwr1.EngineerRequired = true;
            db.MAINT_WORK_REQ.Add(mwr1);
            db.SaveChanges();

            //create Second Record
            MAINT_WORK_REQ mwr2 = new MAINT_WORK_REQ();
            mwr2.ProgramID = "1";
            mwr2.ProjectID = "1";
            mwr2.CreatedBy = "1";
            mwr2.LastModifiedBy = "1";
            mwr2.HSS_FWD = true;
            mwr2.HSS_INB = false;
            mwr2.HSS_OUTB = true;
            mwr2.BODYSTA_FWD = true;
            mwr2.BODYSTA_BOT = true;
            mwr2.BODYSTA_TOP = true;
            mwr2.EngineerRequired = true;
            db.MAINT_WORK_REQ.Add(mwr2);
            db.SaveChanges();

            return View(db.MAINT_WORK_REQ.ToList());
        }
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question