Solved

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

Posted on 2013-11-06
2
554 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

617 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