Question 14


70-486 Skills Measured >> 1.7 Implement synchronous and asynchronous modules and handlers, choose between modules and handlers in IIS >>

Question

Drag and Drop
You are developing an ASP.NET MVC web application in Visual Studio 2012. The application has a model named ReservationLocation that contains properties named City and State. The view that displays reservations has a single text box named loc for entering the location information. The location is entered as city, state. There are action methods that have ReservationLocation as a parameter type. You need to ensure that the City and State properties are correctly populated. How should you implement model binding for the ReservationLocation type? (To answer, drag the appropriate code segment to the correct location or locations. Each code segment may be used once, more than once, or not at all. You may need to drag the split bar between panes or scroll to view content.)

  • bindingContext.ModelType = typeof [ReservationLocation](
  • var raw = bindingContext.ValueProvider.GetValue("loc")
  • dynamic data = binding Context.ValueProvider.GetValue("loc")
  • dynamic data= raw.RawValue.ToString().Split(',');
  • bingContext.ModelStat.Add("city,state",mew ModelState {Value=data})
  • dynamic data = controllerContext.RouteData.Values(raw +"[city,state]"]
public class ReservationModelBinder: IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{


      {
      return new ReservationLocation
      {
      City = data[0]; State = data[1];
      }
      }

      Answer:

      • bindingContext.ModelType = typeof [ReservationLocation](
      • dynamic data = binding Context.ValueProvider.GetValue("loc")
      • bingContext.ModelStat.Add("city,state",mew ModelState {Value=data})
      • dynamic data = controllerContext.RouteData.Values(raw +"[city,state]"]
      public class ReservationModelBinder: IModelBinder
      {
      public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
      {
      • var raw = bindingContext.ValueProvider.GetValue("loc")

      • dynamic data= raw.RawValue.ToString().Split(',');

      return new ReservationLocation
      {
      City = data[0]; State = data[1];
      }
      }
      }