.NET Deck 1 Flashcards

1
Q

Write out the .Net class for this Contact object: (see description)

A

Bob Smith is 30 years old
Has two direct reports. They are:

  • Sally Smith, 30 y/o
  • Jane Doe 34 y/o
public class Contact
{
	public string FirstName {get; set;}
	public string LastName {get; set;}
	public int Age {get; set;}
	public Contact[] Reports {get; set;}
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

If this class was going to participate in Model binding in the MVC request life cycle, is it currently set up to report as invalid when no data is sent to the Server?(Assume FirstName & Last Name are required)

A

With first and last name being required it would check to see if those two are null or not.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What would you have to do to make this model report as “Invalid” in such case?

A
public class Contact
{
         [Required]
[StringLength(maximumLength: 50, MinimumLength = 6,
        ErrorMessage = "The property {0} should have {1} maximum characters and {2} minimum characters")]
	public string FirstName {get; set;}
[Required]
[StringLength(maximumLength: 50, MinimumLength = 6,
        ErrorMessage = "The property {0} should have {1} maximum characters and {2} minimum characters")]
	public string LastName {get; set;}
	public int Age {get; set;}
	public Contact[] Reports {get; set;}
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What namesspace does these attributes live in?

A

Contact

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are all the different types of validations that these attributes let you perform?

A
Required
Range
RegularExpression 
DataType 
EnumDataType
Validation 
StringLength
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Decorate this class to the following specs (see description)

A

First Name and Last Name should be at least 3 chars long and no more than 50

Age should be at least 18 years old

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is Model Binding (ASP.Net) and why is it important?

A

Model binding is a mechanism ASP.NET MVC uses to create parameter objects defined in controller action methods. The parameters can be of any type, from simple to complex ones. It simplifies working with data sent by the browser because data is automatically assigned to the specified model.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are fundamentals that a developer should consider when working to wire up model binding correctly?

A

To have corresponding properties in html tags nested in tags ensure that the “name” attributes matches the property in the model

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the differences between an Api Controller and “regular/view” Controller in .Net?

A

ApiControllers are specialized in returning data and provide a REST-ful API by convention.

“Regular” Controller - contains ActionResult classes that return a View

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

When creating a new controller, what class do you inherit from?

A

controllerBase

How well did you know this?
1
Not at all
2
3
4
5
Perfectly