News:
public class Address { public int AddressType; public string Line1; public string Line2; public string City; public string ZipPostalCode; }
The Web site interacts with an external data service that requires Address instances to be given in the following XML format.
<Address AddressType="2">
<Line1>250 Race Court</Line1>
<City>Chicago</City>
<PostalCode>60603</PostalCode>
</Address>
You need to ensure that Address instances that are serialized by the XmlSerializer class meet the XML format requirements of the external data service. Which two actions should you perform (Each correct answer presents part of the solution. Choose two.)
Add the following attribute to the AddressType field.
[XmlAttribute]
Add the following attribute to the Line2 field.
[XmlElement(IsNullable=true)]
Add the following attribute to the ZipPostalCode field.
[XmlAttribute("ZipCode")]
Add the following attribute to the ZipPostalCode field.
[XmlElement("ZipCode")]
public static void RegisterRoutes(RouteCollectionroutes) { routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx") { Action = PageAction.List,ViewName = "ListDetails", Model = DefaultModel}); routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx") {Action = PageAction.Details,ViewName = "ListDetails",Model = DefaultModel}); }
You need to display the items in a table named Products by using a custom layout. What should you do?
Add a new Web page named Products.aspx to the Dynamic Data\PageTemplates folder of the Web site.
Add a new folder named Products to the Dynamic Data\CustomPages folder of the Web site. Add a new Web page named ListDetails.aspx to the Products folder.
Add a new Web user control named Products.ascx to the Dynamic Data\Filters folder of the Web site.In the code-behind file for the control, change the base class from UserControl to System.Web.
DynamicData.QueryableFilterUserControl.
Add a new Web user control named Products_ListDetails.ascx to the Dynamic Data\EntityTemplates folder of the Web site. In the code-behind file for the control, chan
Add a DynamicDataManager control to the Web page.
Disable the auto-generated fields on GridView1. Add a DynamicField control for each field of the Product class.
Add the following code segment to the Application_Start method in the Global.asax.cs file.
DefaultModel.RegisterContext(typeof(System.Web.UI.WebControls.ObjectDataSource),new ContextConfiguration() {ScaffoldAllTables = true});
Add the following code segment to the Page_Init method of the Web page
GridView1.EnableDynamicData(typeof(Product));
[Authorize(Users = "")]
[Authorize(Roles = "")]
[Authorize(Users = "*")]
[Authorize(Roles = "*")]
01 public static void RegisterRoutes(RouteCollection routes) 02 { 03 routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 05 routes.MapRoute("Default","{controller}/{action}/{id}",new { controller = "Home", action = "Index", id = "" }); 06 }
You implement a controller named HomeController that includes methods with the following signatures.
public ActionResult About() public ActionResult Index() public ActionResult Details(int id)
You need to ensure that the About action is invoked when the root URL of the site is accessed. What should you do?
At line 04 in the Global.asax.cs file, add the following line of code.
routes.MapRoute("Default4Empty", "/", new {controller="Home", action="About"} );
At line 04 in the Global.asax.cs file, add the following line of code.
routes.MapRoute("Default", "", new { controller="Home", action="About"} );
Replace line 05 in the Global.asax.cs file with the following line of code.
routes.MapRoute(v "Default4Empty", "{controller}/{action}/{id}", new {controller="Home", action="About", id=""} );
Replace line 05 in the Global.asax.cs file with the following line of code.
routes.MapRoute("Default", "{controller}/{action}", new {controller="Home", action ="About"});
01 public static void RegisterRoutes (RouteCollection routes) 02 { 03 routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 05 routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = "" }); 06 }
You implement a controller named HomeController that includes methods with the following signatures.
public ActionResult Index() public ActionResult Details(int id) public ActionResult DetailsByUsername(string username)
You need to add a route to meet the following requirements. ?The details for a user must to be displayed when a user name is entered as the path by invoking the DetailsByUsername action. ? User names can contain alphanumeric characters and underscores, and can be between 3 and 20 characters long. What should you do?
Replace line 05 with the following code segment
routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "DetailsByUsername", id = "" });
Replace line 05 with the following code segment.
routes.MapRoute( "Default", "{controller}/{action}/{username}", new { controller = "Home", action = "DetailsByUsername", username = "" }, new { username = @"\w{3,20}" });
At line 04, add the following code segment.
routes.MapRoute("Details by Username", "{username}", new { controller = "Home", action = "DetailsByUsername" }, new { username = @"\w{3,20}" });
At line 04, add the following code segment
routes.MapRoute("Details by Username","{id}",new { controller = "Home", action = "DetailsByUsername" }, new { id = @"\w{3,20}" });
Add the ValidateAntiForgeryToken attribute to the Details action method.
Add the Bind attribute to the country parameter of the Details action method. Set the attribute's Prefix property to Country.
Create a class that implements the IRouteConstraint interface. Configure the default route to use this class.
Create a class that implements the IRouteHandler interface. Configure the default route to use this class.
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.)
Add the following attribute to the first Edit action. [AcceptVerbs(HttpVerbs.Head)]
Add the following attribute to the first Edit action. [HttpGet]
Add the following attribute to the second Edit action. [HttpPost]
Add the following attribute to the second Edit action. [HttpPut]
Add the following method to the CompanyController class.
public ActionResult INFO () { return View(); }
Add the following method to the CompanyController class.
public ActionResult Company_Info() { return View(); }
Right-click the Views folder, and select View from the Add submenu to create the view for the action.
Right-click inside the action method in the CompanyController class, and select Add View to create a view for the action.
<%= Html.RouteLink("Test", "test_default", new {area = "test"}, null) %>
<%= Html.ActionLink("Test", "Details", "Test",new {area = "test"}, null) %>
<a href="<%= Html.RouteLink("Test", "test_default",new {area = "test"}, null) %>">Test</a>
<a href="<%= Html.ActionLink("Test", "Details", "Test",new {area = "test"}, null) %>">Test</a>