Web Developer Framework 4.0 Sample Questions – 15

Question: You are implementing an ASP.NET MVC 2 Web application that contains several folders. The Views/Shared/DisplayTemplates folder contains a templated helper named Score.ascx that performs custom formatting of integer values. The Models folder contains a class named Player with the following definition.
public class Player
{
public String Name { get; set; }
public int LastScore { get; set; }
public int HighScore { get; set; }
}

You need to ensure that the custom formatting is applied to LastScore values when the HtmlHelper.DisplayForModel method is called for any view in the application that has a model of type Player. What should you do?

  1. Rename Score.ascx to LastScore.ascx.
  2. Move Score.ascx from the Views/Shared/DisplayTemplates folder to the Views/Player/DisplayTemplates folder.
  3. Add the following attribute to the LastScore property. [UIHint(“Score”)]
  4. Add the following attribute to the LastScore property. [Display(Name=”LastScore”, ShortName=”Score”)]

Correct Answer: 3


Question: You create an ASP.NET MVC 2 Web application that contains the following controller class.
public class ProductController : Controller
{
static List products = new List();
public ActionResult Index()
{
return View();
}
}

In the Views folder of your application, you add a view page named Index.aspx that includes the following @ Page directive. <%@ Page Inherits=”System.Web.Mvc.ViewPage” %> You test the application with a browser. You receive the following error message when the Index method is invoked: The view ‘Index’ or its master was not found. You need to resolve the error so that the new view is displayed when the Index method is invoked. What should you do?

  1. Change the name of the Index.aspx file to Product.aspx.
  2. Create a folder named Product inside the Views folder. Move Index.aspx to the Product folder.
  3. Replace the @ Page directive in Index.aspx with the following value.
    <%@ Page Inherits="System.Web.Mvc.ViewPage " %>
  4. Modify the Index method by changing its signature to the following:
    public ActionResult Index(Product p)

Correct Answer: 2


Question: You are implementing an ASP.NET MVC 2 Web application that contains the following class.
public class DepartmentController : Controller
{
static List departments = new List();
public ActionResult Index()
{
return View(departments);
}
public ActionResult Details(int id)
{
return View(departments.Find(x => x.ID==id));
}
public ActionResult ListEmployees(Department d)
{
List employees = GetEmployees(d);
return View(employees);
}
}

You create a strongly typed view that displays details for a Department instance. You want the view to also include a listing of department employees. You need to write a code segment that will call the ListEmployees action method and output the results in place. Which code segment should you use?

  1. <%= Html.Action("ListEmployees", Model) %>
  2. <%= Html.ActionLink("ListEmployees", "Department","DepartmentController") %>
  3. <% Html.RenderPartial("ListEmployees", Model); %>
  4. <%= Html.DisplayForModel("ListEmployees") %>

Correct Answer: 1


Question: You are developing an ASP.NET Web application. You create a master page. The master page requires a region where you can add page-specific content by using the ASP.NET page designer. You need to add a control to the master page to define the region. Which control should you add?

  1. Content
  2. ContentPlaceHolder
  3. PlaceHolder
  4. Substitution

Correct Answer: 2


Question: You are developing an ASP.NET Web page that contains input controls, validation controls, and a button named btnSubmit. The page has the following code-behind. (Line numbers are included for reference only.)
01public partial class _Default : System.Web.UI.Page
02{
03protected void SaveToDatabase()
04{
05&
06}
07
08protected void btnSubmit_Click(object sender,EventArgs e)
09{
10
11}
12}
You need to ensure that all data that is submitted passes validation before the data is saved in a database. What should you do?

  1. Add the following method override.
    protected override void OnInit(EventArgs e) {base.OnInit(e);if (Page.IsValid) this.SaveToDatabase(); }
  2. Add the following method override.
    protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (Page.IsValid) this.SaveToDatabase(); }
  3. Add the following method override.
    protected override void OnPreRender(EventArgs e) {base.OnPreRender(e);if (Page.IsValid) this.SaveToDatabase(); }
  4. Add the following code segment at line 10.
    if (Page.IsValid) this.SaveToDatabase();

Correct Answer: 4

Tagged . Bookmark the permalink.

Leave a Reply