Programming Microsoft ASP.NET MVC Flashcards
ASP
Active Server Page
Razor Syntax Rules for C#
- Razor code blocks are enclosed in @{ … }
- Inline expressions (variables and functions) start with @
- Code statements end with semicolon
- Variables are declared with the var keyword
- Strings are enclosed with quotation marks
- C# code is case sensitive
- C# files have the extension .cshtml
Main Razor Syntax Rules for VB
- Razor code blocks are enclosed in @Code … End Code
- Inline expressions (variables and functions) start with @
- Variables are declared with the Dim keyword
- Strings are enclosed with quotation marks
- VB code is not case sensitive
- VB files have the extension .vbhtml
The root on a disk drive C:\ (backwark slash)
The root on a web site is / (forward slash).
~ Operator
Virtual root in programming code
Server.MapPath Method
The Server.MapPath method converts a virtual path (/default.cshtml) to a physical path that the server can understand
- href
- RenderBody()
- RenderPage(page)
- RenderSection(section)
- Write(object)
- WriteLiteral
- Builds a URL using the specified parameters
- Renders the portion of a content page that is not within a named section (In layout pages)
- Renders the content of one page within another page
- Renders the content of a named section (In layout pages)
- Writes the object as an HTML-encoded string
- Writes an object without HTML-encoding it first.
- IsPost
- Layout
- Page
- Request
- Server
- Returns true if the HTTP data transfer method used by the client is a POST request
- Gets or sets the path of a layout page
- Provides property-like access to data shared between pages and layout pages
- Gets the HttpRequest object for the current HTTP request
- Gets the HttpServerUtility object that provides web-page processing methods
non-breaking space
MVC
- Models: Classes that represent the data of the application and that use validation logic to enforce business rules for that data
- Views: Template files that your application uses to dynamically generate HTML responses
- Controllers: Classes that handle incoming browser requests, retrieve model data, and then specify view templates that return a response to the browser
IDE
Integrated development environment
Default MVC URL
/[Controller]/[ActionName]/[Parameters]
C# optional-parameter
- function ( x = 1 )
- = 1 is optional
- &
- ?
- The & character separates query strings
- The ? character separates the URL and query strings
EF
- Entity Framework
- Use for accessing data
Visual Studio automatically created the CRUD action methods and views
(create, read, update, and delete)
@Html.ActionLink(“Edit”, “Edit”, new { id=item.ID })
- The first argument to the ActionLink method is the link text to render
- The second argument is the name of the action method to invoke
- The final argument is an anonymous object that generates the route data
HttpPost attribute
[HttpPost]
This attribute specifies that that overload of the Edit method can be invoked only for POST requests
Bind attribute
public ActionResult Edit([Bind()] )
The Bind attribute is an important security mechanism that keeps hackers from over-posting data to your model
ModelState.IsValid method
Verifies that the data submitted in the form can be used to modify (edit or update) an object
Html.ValidationMessageFor
The Html.ValidationMessageFor helpers in the Edit.cshtml view template take care of displaying appropriate error messages.
LINQ
Language-Integrated Query
The s => s.Title code
Lambda Expression used in method-based LINQ queries as arguments to standard query operator methods