PrepAway - Latest Free Exam Questions & Answers

How should you implement model binding for the ReservationLocation type?

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

PrepAway - Latest Free Exam Questions & Answers

A.
var raw=binding.Context.ValueProvider.GetValue(“loc”);

B.
dynamic data=raw.RawValue.ToString().Slit(‘,’):

C.
dynamic data= binding.Context.ValueProvider.GetValue(“loc”);

Explanation:

2 Comments on “How should you implement model binding for the ReservationLocation type?

  1. dark1500 says:

    This is the working version in visual studio 2019 using MVC (System.Web.Mvc newVersion=”5.2.7.0″)

    public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
    var raw = bindingContext.ValueProvider.GetValue(“loc”);
    var data = raw.AttemptedValue.ToString().Split(‘,’);
    if (data != null && data.Length == 2)
    {
    return new ReservationLocation
    {

    City = data[0],
    State = data[1]
    };
    }
    else return new ReservationLocation();
    }




    0



    0

Leave a Reply