asp.net - How can I update my page details ? in c# with mvc5 -


i want add , update issues on same form. here "sayfa ekle" form. means "add new page"in english.

    public actionresult insert(pages pages, string parent, string optactive)      {     pages pages_ = new pages();          pages_.pagename = pages.pagename;         pages_.pageurl = pages.pageurl;         if (optactive == "on") pages_.isactive = true;         else pages_.isactive = false;         pages_.ordernumber = pages.ordernumber;          int parid = 0;         try         {             parid = convert.toint32(parent);         }         catch         {          }         pages_.parentid = parid;          if (parid == 0) pages_.levelnumber = 0;         else         {             var partemp = db.pages.where(o => o.id ==    parid).firstordefault();             if (partemp.levelnumber == 0) pages_.levelnumber = 1;             else pages_.levelnumber = 2;         }    db.pages.add(pages_);         db.savechanges();         return redirect(url.content("~/page/"));     } 

here adding action. works well.

    [httpget]     private actionresult editpost(string pageid)     {          var id = convert.toint32(pageid);  //edit action         var tmppage = db.pages.where(o => o.id == id).first();         viewbag.tmppage = tmppage;         viewbag.pages = returnpages();          return view("index");     }  

thats editpost action. can retrieve data databas using same form.

<div class="panel panel-success">         <div class="panel-heading text-center">sayfa ekle</div>         <div class="panel-body">              <form action="~/page/insert" method="post">                 <table class="table table-bordered table-striped table-  hover"> <tr>     <td>sayfa adı</td>     <td><input type="text" class="form-control" name="pagename"  placeholder="sayfa ismini giriniz" value="@if (viewbag.tmppage != null) {  @viewbag.tmppage.pagename } " required/></td> </tr> <tr>     <td>sayfa adresi</td>     <td><input type="text" class="form-control" name="pageurl"  placeholder="sayfa adresini giriniz"   required/></td> </tr>  <tr>     <td>aktif/pasif</td>     <td>         <label class="radio-inline">             <input type="radio" name="optactive" value="on" required>aktif         </label>         <label class="radio-inline">             <input type="radio" name="optactive" value="off" required>pasif         </label>      </tr> 

thats view also. how can update records ? i'm using entity frame work code first database. new @ coding. i'll glad if me done internship project.

first of all. missed mvc principle here. try read more bout it.

if using form , model in view need [httppost] before action.

[httppost]   //  public actionresult insert (pages pages)  {         pages pages_ = new pages();         .... 

your method can accept int values, why using string?

[httpget] private actionresult editpost(int? pageid) {     if (pageid == null)          ...do somrthing;      viewbag.tmppage = db.pages.firstordefault(o => o.id == pageid);      viewbag.pages = returnpages();      return view("index"); } 

and view has have model pages in case. , form tag should differently.

   @model pages // first line in view    ...    <form asp-action="insert" asp-controller="pages">        <input asp-for="pagename" class="" />        <input asp-for="isactive" class="" />        .... , etc. 

this partial answer. spend little bit more time reading documentation. however, recommend watch videos, short very-very you.

https://www.youtube.com/playlist?list=plymoucvo86jfpcv6_u2m8p2ne2lsijvln


Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -