What are two possible ways to achieve this goal?

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.)

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.)

A.
Add the following attribute to the first Edit action.
[AcceptVerbs(HttpVerbs.Head)]

B.
Add the following attribute to the first Edit action.
[HttpGet]

C.
Add the following attribute to the second Edit action.
[HttpPost]

D.
Add the following attribute to the second Edit action.
[HttpPut]

Explanation:
There is no [HttpPut] attribute.
[AcceptVerbs] represents an attribute that specifies which HTTP verbs an action method will respond
to. The possible variants are HttpVerbs enumeration: Get, Post, Put, Delete, Head. HttpVerbs
Enumeration (http://msdn.microsoft.com/en-us/library/system.web.mvc.httpverbs.aspx)
CHAPTER 14 Creating Websites with ASP.NET MVC 2
Lesson 2: Creating Models, Views, and Controllers



Leave a Reply 0

Your email address will not be published. Required fields are marked *