Solved

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

Posted on 2013-11-06
2
551 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

734 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