asp.net mvc 2 - MVC2 Entity Framework - Update Model -


first of all, developer on planet attempting use mvc vb? have searched tons of forums , read many posts , asks question gives example in c#. anyway, i've got out of way, i've got simple database table (user) columns (userid, username, firstname, lastname). using entity framework , on edit view, i'm changing value (username) , clicking save. in edit http post, tell return index , value not saved. although, in constructor http post, return object , shows new value...but value doesn't make db...any help?

my controller:

function edit(byval id guid) actionresult         'get user         dim usr = (from u in db.users                   u.userid = id                   select u).single          return view(usr)     end function      <httppost()> _     function edit(byval id guid, byval usrinfo user, byval formvalues formcollection) actionresult         '            dim usr user = db.users.single(function(u) u.userid = id)          if modelstate.isvalid             tryupdatemodel(usrinfo, "user")              return redirecttoaction("index")         else             return view(usrinfo)         end if     end function 

my view:

    <h2>edit</h2>  <%-- following line works around asp.net compiler warning --%> <%: ""%>  <% using html.beginform() %>     <%: html.validationsummary(true) %>     <fieldset>         <legend>fields</legend>          <div class="editor-label">             <%: html.labelfor(function(model) model.userid) %>         </div>         <div class="editor-field">             <%: html.textboxfor(function(model) model.userid) %>             <%: html.validationmessagefor(function(model) model.userid) %>         </div>          <div class="editor-label">             <%: html.labelfor(function(model) model.username) %>         </div>         <div class="editor-field">             <%: html.textboxfor(function(model) model.username) %>             <%: html.validationmessagefor(function(model) model.username) %>         </div>          <div class="editor-label">             <%: html.labelfor(function(model) model.firstname) %>         </div>         <div class="editor-field">             <%: html.textboxfor(function(model) model.firstname) %>             <%: html.validationmessagefor(function(model) model.firstname) %>         </div>          <div class="editor-label">             <%: html.labelfor(function(model) model.lastname) %>         </div>         <div class="editor-field">             <%: html.textboxfor(function(model) model.lastname) %>             <%: html.validationmessagefor(function(model) model.lastname) %>         </div>          <div class="editor-label">             <%: html.labelfor(function(model) model.createddate) %>         </div>         <div class="editor-field">             <%: html.textboxfor(function(model) model.createddate, string.format("{0:g}", model.createddate)) %>             <%: html.validationmessagefor(function(model) model.createddate) %>         </div>          <div class="editor-label">             <%: html.labelfor(function(model) model.createdby) %>         </div>         <div class="editor-field">             <%: html.textboxfor(function(model) model.createdby) %>             <%: html.validationmessagefor(function(model) model.createdby) %>         </div>          <div class="editor-label">             <%: html.labelfor(function(model) model.lastlogin) %>         </div>         <div class="editor-field">             <%: html.textboxfor(function(model) model.lastlogin, string.format("{0:g}", model.lastlogin)) %>             <%: html.validationmessagefor(function(model) model.lastlogin) %>         </div>          <p>             <input type="submit" value="save" />         </p>     </fieldset>  <% end using %>  <div>     <%: html.actionlink("back list", "index") %> </div> 

ok, so, aparently vb developer using mvc. anyway, found answer. in 1 of beginner tutorials mvc on asp.net site (found here). answer change edit function (httppost) utilizes formvalues posted:

<httppost()> _     function edit(byval id guid, byval collection formcollection) actionresult         dim rest = (from r in db.restaurants                 r.restaurantid = id                 select r).single()          try              tryupdatemodel(rest, collection.tovalueprovider())              db.savechanges()              return redirecttoaction("index")         catch             return view(rest)         end try     end function 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -