How to do it...

  1. Add a new folder to your project called Views. Inside that folder, add another folder called Student. Inside the Student folder, add an new item by right-clicking on the Student folder and selecting New Item... from the context menu. From the Add New Item dialog screen, search for the MVC View Page template and call it Find.cshtml.
  1. You should begin to notice that the Views folder, sub folders, and views follow a very specific naming convention. This is because the MVC framework follows a very specific convention, and when you look at the StudentController, this convention will become clear. The Views folder are Views, Student, Find, and the StudentController contains the word Student in the class name and has a method called Find().
You can also create a Shared folder in the Views folder. This is where you place views that are shared across all Controllers and the Controllers will look in the Shared folder by default.
  1. Heading back to the Find.cshtml Razor view, delete the code that is currently in there and replace it with the following:
        <html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
</body>
</html>
You can also use the HTML code snippet. Type html and press Tab twice to insert the boilerplate HTML code into the Find view.
  1. The deal with Razor views is that you are able to write C# expressions directly inside the Find.cshtml file. Before we do this, however, we need to set the type of the model we will be bringing in to our view. We do this using the following directive: @model AspNetCore.Models.Student. We can now reference our Student model directly inside our Razor view with full IntelliSense support. This is done using @Model with an upper case M. Take a look at the changes to the Razor view:
        @model AspNetCore.Models.Student
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Student</title>
</head>
<body>
<div>
<h1>Student Information</h1>
<strong>Student number:</strong>@Model.StudentNumber<br />
<strong>First name: </strong>@Model.FirstName<br />
<strong>First name: </strong>@Model.LastName<br />
</div>
</body>
</html>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.29.22