aspdotnet_codebehind.md - brainchildservices/curriculum GitHub Wiki
Slide 1
To read Values from input Html Control
-
In Html every values are considering as a string. so first we have to convert a string value as per requirement.
public void OnPost() { int length = Int32.Parse(Request.Form["Length"]); int width = Int32.Parse(Request.Form["Width"]); int TotalArea = length * width; this.Result = TotalArea; }
- First line in OnPost Handler Method represents, getting the value for Length from razor page form and setting value to integer variable 'length'.
Slide 2
-
Request.Form is a function of PageModel to get a form
this.Result = TotalArea;
-
the above code means selecting an object property from the same class, to access a class in the same class we use 'this' property.
-
Will discuss more about ModelBinding in next session.
-
Request.Form collections
- The Form collection retrieves the values of form elements posted to the HTTP request body, with a form using the POST method.
- The Form collection is indexed by the names of the parameters in the request body.