c# - MVC4 changing dataobject when selecting item in dropdownlist -


i'm new mvc , i'm not coming right question answer google, here am.

i have dropdownlist box holds 'list' of addresses associated customer, on page want able click on 1 of addresses , use selected 'id' correct address model list populate address fields , switch when different address selected. can done binding or have lot of 'manual' resetting of values?

<table>     <tr>         <td colspan="2">             <div class="form-group">                 @html.labelfor(model => model.selectedlocation.citystate, new { @class = "control-label col-md-2" })                 <div class="col-md-10">                     @html.dropdownlistfor(model => model.location.city                                             , model.carrier.locations.select(x => new selectlistitem { value = x.id.tostring(), text = x.citystate })                                             , new { @rows = 6, @multiple = false, style = "width: 300px;", onchange = "onchangelocationddl(this)" })                 </div>             </div>         </td>     </tr>     <tr>         <td valign="top">             <div class="form-group">                 @html.labelfor(model => model.selectedlocation.address1, new { @class = "control-label col-md-2" })                 <div class="col-md-10">                     @html.editorfor(model => model.selectedlocation.address1)                     @html.validationmessagefor(model => model.selectedlocation.address1)                 </div>             </div>              <div class="form-group">                 @html.labelfor(model => model.selectedlocation.address2, new { @class = "control-label col-md-2" })                 <div class="col-md-10">                     @html.editorfor(model => model.selectedlocation.address2)                     @html.validationmessagefor(model => model.selectedlocation.address2)                 </div>             </div>              <div class="form-group">                 @html.labelfor(model => model.selectedlocation.city, new { @class = "control-label col-md-2" })                 <div class="col-md-10">                     @html.editorfor(model => model.selectedlocation.city)                     @html.validationmessagefor(model => model.selectedlocation.city)                 </div>             </div>              <div class="form-group">                 @html.labelfor(model => model.selectedlocation.state, new { @class = "control-label col-md-2" })                 <div class="col-md-10">                     @html.editorfor(model => model.selectedlocation.state)                     @html.validationmessagefor(model => model.selectedlocation.state)                 </div>             </div>              <div class="form-group">                 @html.labelfor(model => model.selectedlocation.zip, new { @class = "control-label col-md-2" })                 <div class="col-md-10">                     @html.editorfor(model => model.selectedlocation.zip)                     @html.validationmessagefor(model => model.selectedlocation.zip)                 </div>             </div>          </td>         <td valign="top">              <div class="form-group">                 @html.labelfor(model => model.selectedlocation.country, new { @class = "control-label col-md-2" })                 <div class="col-md-10">                     @html.editorfor(model => model.selectedlocation.country)                     @html.validationmessagefor(model => model.selectedlocation.country)                 </div>             </div>              <div class="form-group">                 @html.labelfor(model => model.selectedlocation.latitude, new { @class = "control-label col-md-2" })                 <div class="col-md-10">                     @html.editorfor(model => model.selectedlocation.latitude)                     @html.validationmessagefor(model => model.selectedlocation.latitude)                 </div>             </div>              <div class="form-group">                 @html.labelfor(model => model.selectedlocation.longitude, new { @class = "control-label col-md-2" })                 <div class="col-md-10">                     @html.editorfor(model => model.selectedlocation.longitude)                     @html.validationmessagefor(model => model.selectedlocation.longitude)                 </div>             </div>              <div class="form-group">                 @html.labelfor(model => model.selectedlocation.locationtype, new { @class = "control-label col-md-2" })                 <div class="col-md-10">                     @html.dropdownlistfor(model => model.selectedlocation.locationtype, (new carrierdirectoryweb.models.locationtypes()).toselectlist())                     @html.validationmessagefor(model => model.selectedlocation.locationtype)                 </div>             </div>              <div class="form-group">                 <div class="col-md-10">                     @html.hiddenfor(model => model.selectedlocation.carrierid)                 </div>             </div>         </td>     </tr>   </table> 

if ok hitting controller update part of page here how it:

-create partial view html responsible displaying address.

-have original view call partial , pass in address model.

-create action take id , return partialviewresult.

-pass onchange html attribute dropdown should 1 liner using jquery call action method , replace div contains address.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

django - CSRF verification failed. Request aborted. CSRF cookie not set -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -