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.

  16. Lars Erik Grambo said

    Cringe-trigger at 14:25. Using var keyword for a well known type. ugh.... Why? Whyyy?

  17. zakkatkk said

    Oh, I see why they didn't bother doing the database integration in this episode now. I assumed I had done all of the MVC tutorials, but there are a few more behind the paywall that focus on the database. I wish I could delete my previous comment.

  18. Faculty

    Eric J Fisher said

    Lars laughing var is absolutely a very hot topic in .NET. No where near as hot as tabs vs spaces, but still you other love it or loath it. When it first came out I was like "no thanks" but it's grown on me over the years. (perhaps I had to do too much javascript these past few years, either way use it if you want, don't use it if you don't the resulting complied code is the same) it's basically .Net's new "tabs vs spaces".

  19. Faculty

    Eric J Fisher said

    @zakkatkk I deleted the comment for you :) Yeah, we introduce the very basics in the Try ASP.NET then dig more into Database, etc in Forging Ahead with ASP.NET.

  20. Alem Putes said

    Wow didn't expect this, have been using Pluralsight for some time and never experienced this, here you are stuck on LOADING, LOADING all too often. How do you expect people to use your site when its not optimized. 1 star from me, if you can't use the site properly then no point in using it at all.

  21. michaelcullina said

    I enjoyed this screencast.

  22. pendell said

    Excellent screencast. If you get the opportunity, I'd like to see more on C# lambdas, as it's a thing in the language I could really stand to brush up on.

    Also, while I get you just want to get something up and running as quickly as possible .. perhaps it's not the best thing to demonstrate how to use global variables to beginning programmers? Given the fact that if they ever use one in a job interview they'll be laughed out of the room.

  23. Faculty

    Eric J Fisher said

    I'm glad you liked it!

    In our second course and screencast on ASP.NET we do touch lambda / linq a little more. (but only a little) We also utilize a database using EntityFramework to avoid the need for a global variable.

    I do agree though global variables should only be used in very specific cases where they make sense which tend to be few and far between. Unfortunately in trying to keep the length of this screencast and the introductory course short we didn't cover a proper way to work around the need for a global in a timely manner. The issue being we wanted the data to persist, but without complicating the code such that it would take significantly longer to write/explain or creating some form of data storage we didn't have a good way to avoid it, which is part of why we specifically went out of our way to say "Hey we're doing this because time, but this isn't the best way of handling this problem"

    The second course and screencast though we use proper data storage and avoid using a global variable.

  24. Student #4183823 said

    Enjoyed the course but creating the project to follow along with in VS2017 - I created the same project type but the Controllers and Views directory were not automatically created. I went back to see if I missed a step and it looked good. I simply added folders that weren't there and got to the point where the first run of the Game screen and it would not display. Were there any issues that you know creating this project in VS2017 with Creators Update?

  25. careuno said

    hi, why don't you create a new project using Visual Studio for Mac instead of CLI?

  26. Faculty

    Eric J Fisher said

    @careuno If I were to remake this video today, I would create the project using Visual Studio for OSX, however; at the time of this recording Visual Studio for OSX wasn't fully released and ASP.NET Core tooling on Visual Studio for OSX had some quirkiness. So instead we used the CLI as that time it was the most common way to make new ASP.NET Core projects on OSX.

    That said, all the material is still up to date for the current versions of ASP.NET core. These days I generally use Visual Studio for OSX or Visual Studio 2017 on Windows. (depending on what computer I'm on) but using the CLI still works and results in the same starting template and I do use it on occasion. :)

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