Web Developer Framework 4.0 Sample Questions – 14

Question: You are implementing an ASP.NET MVC 2 Web application. The URL with path /Home/Details/{country} will return a page that provides information about the named country. You need to ensure that requests for this URL that contain an unrecognized country value will not be processed by the Details action of HomeController. What should you do?

  1. Add the ValidateAntiForgeryToken attribute to the Details action method.
  2. Add the Bind attribute to the country parameter of the Details action method. Set the attribute s Prefix property to Country.
  3. Create a class that implements the IRouteConstraint interface. Configure the default route to use this class.
  4. Create a class that implements the IRouteHandler interface. Configure the default route to use this class.

Correct Answer: 3


Question: You are implementing an ASP.NET MVC 2 Web application. A controller contains the following code.
public ActionResult Edit(int id)
{
return View(SelectUserToEdit(id));
}
public ActionResult Edit(Person person)
{
UpdateUser(person);
return RedirectToAction("Index");
}

The first Edit action displays the user whose details are to be edited, and the second Edit action is called when the Save button on the editing form is clicked to update the user details. An exception is thrown at run time stating that the request for action Edit is ambiguous. You need to correct this error and ensure that the controller functions as expected. What are two possible ways to achieve this goal? (Each correct answer presents a complete solution. Choose two.)

  1. Add the following attribute to the first Edit action.
    [AcceptVerbs(HttpVerbs.Head)]
  2. Add the following attribute to the first Edit action.
    [HttpGet]
  3. Add the following attribute to the second Edit action.
    [HttpPost]
  4. Add the following attribute to the second Edit action.
    [HttpPut]

Correct Answer: 2 & 3


Question: You are implementing an ASP. NET MVC 2 Web application. You add a controller named CompanyController. You need to modify the application to handle the URL path /company/info. Which two actions should you perform? (Each correct answer presents part of the solution. Choose two.)

  1. Add the following method to the CompanyController class.
    public ActionResult I nfo () { return View(); }
  2. Add the following method to the CompanyController class.
    public ActionResult Company_Info () { return View(); }
  3. Right-click the Views folder, and select View from the Add submenu to create theview for the action.
  4. Right-click inside the action method in the CompanyController class, and selectAdd View to create a view for the action.

Correct Answer: 1 & 4


Question: You are implementing an ASP.NET MVC 2 application. In the Areas folder, you add a subfolder named Product to create a single project area. You add files named ProductController.cs and Index.aspx to the appropriate subfolders. You then add a file named Route.cs to the Product folder that contains the following code. (Line numbers are included for reference only.)
01 public class Routes : AreaRegistration
02 {
03 public override string AreaName
04 {
05 get { return “product”; }
06 }
07
08 public override void RegisterArea(AreaRegistrationContext context)
09 {
10 context.MapRoute(“product_default”, “product/{controller}/{action}/{id}”, new {controller = “Product”, action = “Index”, id = “” });
11 }
12 }
When you load the URL Error! Hyperlink reference not valid., you discover that the correct page is not returned. You need to ensure that the correct page is returned. What should you do?

  1. Replace line 10 with the following code segment.
    context.MapRoute("product_default","{area}/{controller}/{action}/{id}", new{area=”product”, controller = “Product”, action = “Index”, id = “” });
  2. Replace line 10 with the following code segment.
    context.MapRoute("product_default","{area}", new { controller = "Product", action =“Index”, id = “”});
  3. Add the following code segment at line 11.
    AreaRegistration.RegisterAllAreas();
  4. Add the following code segment to the RegisterRoutes method in theGlobal.asax.cs file.
    AreaRegistration.RegisterAllAreas();

Correct Answer: 4


Question: You are implementing an ASP.NET MVC 2 Web application. You create a shared user control named MenuBar.ascx that contains the application s menu. You need to use the menu bar in all application views. What should you do?

  1. In the site s master page, create a div element with an ID of Navigation. Add the following code segment inside this div element.
    <% Html.RenderPartial ("~/Views/Shared/ MenuBar.ascx "); %>
  2. In the site s master page, create a div element with an ID of Navigation. Add the following code segment inside this div element.
    <%= Url.Content ( "~/Views/Shared/ MenuBar.ascx ") %>
  3. In each of the controller s action methods, add an entry to the ViewData collection with a key of Navigation and a value of ~/Views/Shared/MenuBar.ascx.
  4. In the site s Global.asax.cs file, register a route named Navigation that points to the ~/Views/Shared/MenuBar.ascx file.

Correct Answer: 1

Tagged . Bookmark the permalink.

One Response to Web Developer Framework 4.0 Sample Questions – 14

  1. Francis says:

    This is what we need – an insight to make everyone think..

Leave a Reply