Using Strongly Typed Views

Get back to our controller class.

Let's assign the model to our Controller model.

var comicBook = new ComicBook();

// right-click and choose "quick actions .. " and choose using model.

Because we have already set our Model. Now, we can finish it like using OOP.

var comicBook = new ComicBook()
{
    SeriesTitle = "The Amazing Spider-Man",
    IssueNumber = 700,
    DescriptionHTML = "<p>Final issue! Witness the final hours of Doctor Octopus' life and his one, last, great act of revenge! Even if Spider-Man survives... <strong>will Peter Parker?</strong></p>",
    Artists = new Artist[]
    {
        new Artist() {Name= "Dan Slott", Role="Script"},
        new Artist() {Name= "Humberto Ramos", Role="Pencils"},
        new Artist() {Name= "Victor Olazaba", Role="Inks"},
        new Artist() {Name= "Edgar Delgado", Role="Colors"},
        new Artist() {Name= "Chris Eliopoulos", Role="Letters"}
    }
};

Finally, we would like to return our comicbook variable to View.

public ActionResult Detail()
{
    var comicBook = new ComicBook()
    {
        SeriesTitle = "The Amazing Spider-Man",
        IssueNumber = 700,
        DescriptionHTML = "<p>Final issue! Witness the final hours of Doctor Octopus' life and his one, last, great act of revenge! Even if Spider-Man survives... <strong>will Peter Parker?</strong></p>",
        Artists = new Artist[]
        {
            new Artist() {Name= "Dan Slott", Role="Script"},
            new Artist() {Name= "Humberto Ramos", Role="Pencils"},
            new Artist() {Name= "Victor Olazaba", Role="Inks"},
            new Artist() {Name= "Edgar Delgado", Role="Colors"},
            new Artist() {Name= "Chris Eliopoulos", Role="Letters"}
        }
    };

    return View(comicBook);
}

results matching ""

    No results matching ""