javascript - Passing model data to partial view after updating model again -


i having main view , few partial views.

the main view displays list of registered users : enter image description here

the main view code :

@model webapplication9.models.user  @{     layout = null; }  <!doctype html>  <html> <head>     <meta name="viewport" content="width=device-width" />     <title>index</title>     <link ref="~/styles/usermanagement.css" rel="stylesheet" />     <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>      <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">     <script src="https://code.jquery.com/jquery-1.12.4.js"></script>     <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> </head> <body>     <p>         <button type="submit" name="btndefinetraj" onclick="adduserbtnclick()" id="button1">create new user</button>     </p>      <div hidden id="divadduser" title="add new user" style="border-radius: 7px">         @html.partial("~/views/usermanagement/createuser.cshtml")     </div>          <div hidden id="divedituser" title="edit user" style="border-radius: 7px">         @html.partial("~/views/usermanagement/edituser.cshtml", model)     </div>      <table>         <tr>             <th>userid             </th>             <th>username             </th>             <th>password             </th>             <th>firstname             </th>             <th>lastname             </th>             <th>displayname             </th>             <th>email             </th>             <th>pref. language             </th>             <th>createdby             </th>             <th>createdtime             </th>             <th>modifiedtime             </th>             <th>isadmin             </th>             <th>isactive             </th>             <th></th>         </tr>          @foreach (var item in model.userslist)         {             <tr>                 <td>                     @html.displayfor(modelitem => item.userid)                 </td>                 <td>                     @html.displayfor(modelitem => item.username)                 </td>                 <td>                     @html.displayfor(modelitem => item.password)                 </td>                 <td>                     @html.displayfor(modelitem => item.firstname)                 </td>                 <td>                     @html.displayfor(modelitem => item.lastname)                 </td>                 <td>                     @html.displayfor(modelitem => item.displayname)                 </td>                 <td>                     @html.displayfor(modelitem => item.email)                 </td>                 <td>                     @html.displayfor(modelitem => item.languagepreference)                 </td>                 <td>                     @html.displayfor(modelitem => item.createdby)                 </td>                 <td>                     @html.displayfor(modelitem => item.createdtime)                 </td>                 <td>                     @html.displayfor(modelitem => item.modifiedtime)                 </td>                 <td>                     @html.displayfor(modelitem => item.isadmin)                 </td>                 <td>                     @html.displayfor(modelitem => item.isactive)                 </td>                 <td>                     <button type="submit" name="btnedituser" onclick="edituserbtnclick(@item.userid)" id="buttonedit">                         <img src="~/images/edit-icon.png" width="20" height="20" />                     </button>                 </td>                 <td>                     <button type="submit" name="btndeleteuser" onclick="deleteuserbtnclick(@item.userid)" id="buttondelete">                         <img src="~/images/delete-icon.png" width="20" height="20" /></button>                     @*                @html.actionlink("edit", "edituser", new { id=item.userid } ) |                 @html.actionlink("delete", "deleteuser", new { id=item.userid })*@                 </td>             </tr>         }      </table> </body> </html> 

my model class user code :

public class user {     public int userid { get; set; }     public string username { get; set; }     public string password { get; set; }     public string firstname { get; set; }     public string lastname { get; set; }     public string displayname { get; set; }     public string emailid { get; set; }     public string languagepreference { get; set; }     public bool isadministrator { get; set; }     public bool isactive { get; set; }     public ienumerable<usermaster> userslist{ get; set; }     public usermaster edituserdata { get; set; } } 

as can see, table loaded userslist in model. trying implement edit user functionality. when user clicks on edit button opening partial view :

<div hidden id="divedituser" title="edit user" style="border-radius: 7px"> @html.partial("~/views/usermanagement/edituser.cshtml", model) </div> 

by passing id controller , getting user data can displayed in new partial view

function edituserbtnclick(userid) { $.ajax({     type: "post",     url: "/usermanagement/edituser",     data: json.stringify({ userid: userid }),     contenttype: "application/json; charset=utf-8",     datatype: "json",     success: function (edituserdataobj) {         if (msg != null) {             $("#divedituser").dialog({ width: 350 });         }         else {             $('#lblresult').val("failed delete user.");         }     },     error: function () {         return "error";     } }); 

i getting edituserdataobj here. not sure how pass partial view edituser.cshtml. tried edit model adding new edit user data model class property public usermaster edituserdata { get; set; }. when access partial view, data null.

[httppost] public jsonresult edituser(int userid) {     var user = dbmanager.instance.getuserdata(userid);     return json(user); } 

is there way pass edit user data partial view?


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -