javascript - EnumDropDownListFor Change ajax call action and the selected value assign to one field of database -


i want update vazlist in database record it's enumdropdownlistfor item has been changed. want selected value assigned vazlist of record.

@using (html.beginform("index", "my", formmethod.post)) {  <p>     @html.actionlink("create new", "create") </p> <table class="table">     <tr>         <th>             @html.displaynamefor(model => model.name)         </th>         <th>             @html.displaynamefor(model => model.lastname)         </th>         <th>             @html.displaynamefor(model => model.nationalidnumber)         </th>         <th>             @html.displaynamefor(model => model.cellphonenumber)         </th>         <th>             @html.displaynamefor(model => model.emailaddress)         </th>          <th>             @html.displaynamefor(model => model.vahedlist)         </th>         <th>             @html.displaynamefor(model => model.vazlist)         </th>         <th></th>     </tr>  @foreach (var item in model)     {         <tr>             <td>                 @html.displayfor(modelitem => item.name)             </td>             <td>                 @html.displayfor(modelitem => item.lastname)             </td>             <td>                 @html.displayfor(modelitem => item.nationalidnumber)             </td>             <td>                 @html.displayfor(modelitem => item.cellphonenumber)             </td>             <td>                 @html.displayfor(modelitem => item.emailaddress)             </td>              <td>                 @html.displayfor(modelitem => item.vahedlist)             </td>             <td>                 @html.enumdropdownlistfor(modelitem=>item.vazlist)                 <input class="btn btn-default" type="submit" value="ثبت">             </td>             <td>                 @html.actionlink("edit", "edit", new { id = item.id }) |                 @html.actionlink("details", "details", new { id = item.id }) |                 @html.actionlink("delete", "delete", new { id = item.id })             </td>         </tr>     }     </table> } </body> <script src="~/scripts/jquery-1.10.2.min.js"></script> <script> $("#item_vazlist").change(function () {     $.ajax({         url: "@url.action("indexa", "my")",         datatype: "text",         type: "post",         success: function (data) {             alert("successful process");         },         error: function () {             $("#testarea").html("error");         }     }); }); 

and action conroller:

 [httppost]  public actionresult indexa(viewmodelperson model, int? id)  {      databasecontext db=new databasecontext();      efperson efp = db.people.find(id);       efp.vazlist = model.vazlist;      db.people.attach(efp);      db.entry(efp).state = entitystate.modified;      db.savechanges();       // other changed properties       return redirecttoaction("sabt");  } 

i need vazlist updated selected item.
sorry if english not ok.
please me thank you.

assuming item has id property, update line to:

@html.enumdropdownlistfor(modelitem=>item.vazlist, new { data_id = item.id }) 

this add data parameter html <select data-id="id" > (assuming using mvc 3+).

then update ajax call to:

$.ajax({     url: "@url.action("indexa", "my")",     datatype: "text",     type: "post",     data: { id : $(this).data("id") }, //<--new part, id      success: function (data) {         alert("successful process");     },     error: function () {         $("#testarea").html("error");     } }); 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -