Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot code along easily with the lecture #2

Open
PostalMike opened this issue Jul 27, 2016 · 1 comment
Open

Cannot code along easily with the lecture #2

PostalMike opened this issue Jul 27, 2016 · 1 comment

Comments

@PostalMike
Copy link

PostalMike commented Jul 27, 2016

Update -- I downloaded the code from Git Hub as opposed to trying to create it myself as I followed along. Doing so and directly opening the .sln files from the downloaded code, brings up VS 2015, not our current version, VS 2013. This now makes the code I'm viewing during the lectures exactly the same. There were differences while viewing along with 2013.

This is partly a learning curve scenario for me with MVC.

At some point I got an error trying to follow along with the lectures, creating the code myself and ended up using the Package Console to install EF 6.1.3. VERY bad idea. Then I got other error messages explaining what happened (EF 6.1.3 not compatible, basically) and trying to fix it created other problems.

End result was ... I just deleted all the solutions I had up to the middle of the 3rd lecture, The Power of Visual Studio.

It would be a lot to ask for a PPT deck showing what to add where to do the code on my own. But if I had this I could get close to where I'm at now. Jon Galloway just put in the code for either Artists or Albums at time index 25:39, something like that and I'm left holding the bag. :)

Other than that, great video and I love it. The upside is, re-creating everything will be great practice. Again, if there could also be a PPT display saying "Here's what you do to create the code for Module 2, here's Module 3, etc." this would be great. As if you're work isn't detailed enough already, right? :)

Thanks.

@amenefus
Copy link

Dear PostalMike,
I also had this issue with the model Reviews which gives you the drop down list to AlbumsID & Albums title.
notice that they edited the controller to do so.
read the code on the controller section:
`
public ActionResult Index()
{
// added lamda expression to include Album in the list.
var reviews = db.Reviews.Include(r => r.Album);
return View(reviews.ToList());
}

    // GET: Reviews/Details/5  ** (Microsoft default stuff) **
    public ActionResult Details(int? id)
    {
        if (id == null)
        {
            return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        }
        Review review = db.Reviews.Find(id);
        if (review == null)
        {
            return HttpNotFound();
        }
        return View(review);
    }

    // GET: Reviews/Create **added create drop down list (!!) for the review controller. **
    public ActionResult Create()
    {
        ViewBag.AlbumID = new SelectList(db.Albums, "AlbumID", "Title");
        return View();
    }

    // POST: Reviews/Create
    // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
    // more details see https://go.microsoft.com/fwlink/?LinkId=317598.
    [HttpPost]
    [ValidateAntiForgeryToken]
    // again with binding it 
    public ActionResult Create([Bind(Include = "ReviewID,AlbumID,Contents,ReviewerEmail")] Review review)
    {
        if (ModelState.IsValid)
        {
            db.Reviews.Add(review);
            db.SaveChanges();
            return RedirectToAction("Index");
        }
       //this is a view state which will give you the state itself of what you created with the album props
        ViewBag.AlbumID = new SelectList(db.Albums, "AlbumID", "Title", review.AlbumID);
        return View(review);
    }

    // GET: Reviews/Edit/5
    public ActionResult Edit(int? id)
    {
        if (id == null)
        {
            return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        }
        Review review = db.Reviews.Find(id);
        if (review == null)
        {
            return HttpNotFound();
        }
        ViewBag.AlbumID = new SelectList(db.Albums, "AlbumID", "Title", review.AlbumID);
        return View(review);
    }

    // POST: Reviews/Edit/5
    // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
    // more details see https://go.microsoft.com/fwlink/?LinkId=317598.
    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult Edit([Bind(Include = "ReviewID,AlbumID,Contents,ReviewerEmail")] Review review)
    {
        if (ModelState.IsValid)
        {
            db.Entry(review).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("Index");
        }
        ViewBag.AlbumID = new SelectList(db.Albums, "AlbumID", "Title", review.AlbumID);
        return View(review);
    }

`

the relationships on the models had not been created properly by visual studio so they created it on the controller operation .

if i missed somthin let me know

Michael.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants