dimanche 26 juillet 2015

Checkbox Toggle to Set Address Fields

I'm using asp.net + MVC and trying to build an interface where one would enter the address of a facility. In some instances, the facility can have the same address as the institution it belongs to and I’m using a checkbox (EditFor field) to indicate if the address is the same as the institution. The view is strongly typed to a Facility class and this class has a virtual property to the Institution class. My issue is when one clicks the checkbox I would like the code to update the address fields to either display the institution’s address or clear the fields so one can enter a different address. I have some javascript that I used to hide/show the address fields but that’s not really what I want. How can I collect the model data i.e. Institution and Facility and place it in the EditFor fields?

Checkbox Field

<div class="form-group">
     @Html.LabelFor(model => model.Address1, htmlAttributes: new { @class = "control-label col-md-2" })
     <div class="col-md-10">
          @Html.EditorFor(model => model.Address1, new { htmlAttributes = new { @class = "form-control" } })
          @Html.ValidationMessageFor(model => model.Address1, "", new { @class = "text-danger" })
     </div>
</div>

JavaScript

$("#AddressSameAsInstitute").click(function () {
        $(".set-from-checkbox").toggle(!this.checked);
    });




Aucun commentaire:

Enregistrer un commentaire