Solved

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

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

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 improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now