Screencast Build a .NET MVC App .NET

  • Eric J Fisher


  1. Chad Hollman said

    It would be cool if CodeSchool created another screencast in which EntityFramework was added to this project and replaced the global variables.

  2. Faculty

    Eric J Fisher said

    Hello @ChadHollman! The upcoming Forging Ahead With .NET MVC actually focusses a great deal on the database interaction in ASP.NET MVC through Entity Framework, and it's corresponding Watch Us Build will also demonstrate setting up an ASP.NET Core application on OS X to use SQL Lite via EntityFramework from start to finish. In other words Stay tuned it's coming! :)

  3. Chad Hollman said

    I must also add that this has been on of the better STB/WUB screencasts out of CodeSchool. Great job, thank you!

  4. Manny Garcia said

    Uhmm - I'm new to this so here I go - In MVS2013 I get Error 1
    Invalid token '=' in class, struct, or interface member declaration 2013\Projects\GameReviewer\GameReviewer\Models\GlobalVariables.cs 10 54 GameReviewer

    using System.Collections.Generic; using GameReviewer.Models;

    namespace GameReviewer { public static class GlobalVariables { public static List Games { get; set; } = new List(); } }

    Is there a different way to do this? Just coding while watching your awesome video. Thank you.

  5. Faculty

    Stefan Nychka said

    HI Manny! Responding on behalf of Eric. He'll improve later if needed.

    It sounds like it may be that you're using Visual Studio 2013 instead of vs 2015. Or maybe that you're not using .NET Core. (Note that's different than the standard .NET).

    Also, note a workaround may be for you to just avoid that inline initialization, and init. elsewhere, like in the constructor.

    The inline initialization of a property is apparently a bit new. Let us know if one of those is the case!

  6. Manny Garcia said

    Thank you Stefan! Solved the issue on VS2013 like this:

    public static class GlobalVariables { public static List Games { get { return Games; } set { Games = new List(); }

  7. Anna Oleksiak said

    I've followed the screencast in VS2013. There are some features used here that didn't exist back in C#5.0 and APS.NET MVC5 (aka VS2013). Here are my workarounds (I only put those code fragments that are different)

    1. Creating input form ... ActualLabel

    2. Adding link to another view 2.1 Generate whole element @Html.ActionLink("link-text", "action-method", "controller-class", new { parameter-name="parameter-value" }, null) 2.2 Generate only the path to put in @Url.Action("action-method", "controller-class", new { parameter-name="parameter-value" })

    3. Pass on URL parameters to POST call In place of put: @using( Html.BeginForm ( "action-method", "controller-class", new { parameter-name="parameter-value" }, FormMethod.Post, null){ <label... <input... ... } What got me stuck for quite a while was a difference in passing on ViewData["Game"]: asp-route-gamename="@ViewData["Game"]" versus new { gameName=ViewData["Game"] }

    4. Inline initialization of property appeared in C#6.0; one of the old ways to initialize a property is:

    private List games = new List(): public List Games { get { return games; } set { games = value; } }

  8. Anna Oleksiak said

    I'll try to post it again in several comments, with maybe some line breaks in right places this time. I won't close html elements because they failed to appear at all.

    1. Creating input form

    <form action="action-method" method="post"

    <label for="id-of-input" //put actual label text inside label element

    <input id="input-id" name="same-property-name-as-asp-for"

  9. Anna Oleksiak said

    2.1 Adding link to another view - generate whole <a element

    @Html.ActionLink("link-text", "action-method", "controller-class", new { parameter-name="parameter-value" }, null)

    2.2 Adding link to another view - generate only path to put in <a href="path"

    @Url.Action("action-method", "controller-class", new { parameter-name="parameter-value" })

  10. Anna Oleksiak said

    1. Pass on URL parameters to POST call (replace <form element with this code)

    @using( Html.BeginForm ( "action-method", "controller-class", new { parameter-name="parameter-value" }, FormMethod.Post, null)

    { <label... <input... }

    Note: new { gameName=ViewData["Game"] }.

  11. Anna Oleksiak said

    1. One of the "old" ways to do property initialization, since inline initialization is a C#6.0 feature.

    private List<Game games = new List<Game():

    public List<Game Games {

    get { return games; }

    set { games = value; }


  12. Derek Lowrance said

    I'm trying to figure out why I'm getting a null reference exception when attempting to attach the review to the game.

    public IActionResult Create(Review review, string gameName) { var game = Game.Read(gameName); game.AddReviewToGame(review); <------This is where my application stops return RedirectToAction("Index","Game"); }

  13. Faculty

    Eric J Fisher said

    Getting a null exception at the specified line implies the line var game = Game.Read(gameName); failed to return a record. That means either A. the record was never added or B. the record wasn't successfully retrieved (I would guess the string gameName isn't getting passed in properly, you can check this with a breakpoint or adding a line Console.WriteLine("gameName: " + gameName); as the first line in this method and watching for the message in the console. This means something is wrong with your Read method (which I'm assuming matches my Getmethod) or their is something wrong with Create method that is quietly failing to create the record to begin with. I have the app code available if you would like to compare, but I would check to make sure your gameName is getting passed in properly first, it's a pretty common place people make mistakes.

  14. Derek Lowrance said

    Oh jeez, I had gotten interrupted at work yesterday and never finished the video. I spent so much time figuring out that I needed to add "asp-route-gamename="@game.Name"" hahaha!

    Thanks for the help Eric.

  15. Internet Developers said

    Thanks for the course. It was very easy to follow and understand.

About This Screencast

In this episode, we will expand upon what we learned from the Try ASP.NET Core course and build a real-world ASP.NET Core application. We will be setting up the applications in both OS X and Windows, but focusing the build on just the Windows side.

You need to be an enrolled student in order to view this video and subscribe.

Enroll Now