asp.net mvc 4 - MVC 4 Add/Update list in a partial view -


this first program , quite not sure on how complete codes. trying create new transaction, supplier there multiple inventory types. lost on how add inventory types list using partial view. guidance on how structure code appreciated. here codes:

viewmodels:

public class inventorytransactionparent     {         [key]         public int inventorytransactionid { get; set; }          [foreignkey("inventorytransactiontype")]         [display(name = "transaction type")]         public int inventorytransactiontypeid { get; set; }         public virtual inventorytransactiontype inventorytransactiontype { get; set; }          [display(name = "supplier")]         [foreignkey("supplier")]         public int? supplierid { get; set; }         public virtual supplier supplier { get; set; }          [display(name = "transaction date (from previous month only)")]         [displayformat(applyformatineditmode = true, dataformatstring = "{0:dd/mm/yyyy}")]         public datetime inventorytransactiondate { get; set; }          [display(name = "receipt/invoice no.")]         public string inventorytransactionreceipt { get; set; }          [display(name = "transaction by")]         public string inventorytransactionby { get; set; }          [display(name = "created on")]         public datetime inventorytransactioncreateddatetime { get; set; }          [display(name = "created by")]         public string inventorytransactioncreatedby { get; set; }          public bool inventorytransactioncancelled { get; set; }         public int? inventorytransactioncancelledsourceid { get; set; }          public list<inventorytypechild> inventorytypechilds { get; set; }     }  public class inventorytypechild     {         [foreignkey("inventorytype")]         [display(name = "inventory type")]         public int inventorytypeid { get; set; }         public virtual inventorytype inventorytype { get; set; }          [display(name = "quantity")]         public decimal inventorytransactionquantity { get; set; }          [display(name = "price per item")]         public decimal inventorytransactionprice { get; set; }          [display(name = "remarks (1000 characters)")]         [datatype(datatype.multilinetext)]         public string inventorytransactionremarks { get; set; }     } 

view:

@model inventory.viewmodels.inventorytransactionparent     @using (html.beginform()) {     @html.validationsummary(true)      <fieldset>         <legend>in transaction</legend>           <div class="editor-label">             @html.labelfor(model => model.supplierid, "supplier")         </div>         <div class="editor-field">             @html.dropdownlist("supplierid", string.empty)             @html.validationmessagefor(model => model.supplierid)         </div>          <div class="editor-label">             @html.labelfor(model => model.inventorytransactiondate)         </div>         <div class="editor-field">             @html.editorfor(model => model.inventorytransactiondate, "transactiondate")         </div>          <div class="editor-label">             @html.labelfor(model => model.inventorytransactionreceipt)         </div>         <div class="editor-field">             @html.editorfor(model => model.inventorytransactionreceipt)             @html.validationmessagefor(model => model.inventorytransactionreceipt)         </div>         <div id="inventorytypes">             @using (html.beginform()) {                 <table>                     <tr>                         <td>@html.labelfor(model => model.inventorytypechilds[0].inventorytypeid)</td>                         <td>@html.labelfor(model => model.inventorytypechilds[0].inventorytransactionprice)</td>                         <td>@html.labelfor(model => model.inventorytypechilds[0].inventorytransactionquantity)</td>                         <td>@html.labelfor(model => model.inventorytypechilds[0].inventorytransactionremarks)</td>                         <td></td>                     </tr>                 @{                     if (model.inventorytypechilds != null)                     {                         (int = 0; < model.inventorytypechilds.count(); i++)                         {                             <tr>                                 <td>                                     @html.dropdownlist("inventorytypeid", string.empty)                                     @html.validationmessagefor(model => model.inventorytypechilds[i].inventorytypeid)                                 </td>                                 <td>                                     @html.editorfor(model => model.inventorytypechilds[i].inventorytransactionprice)                                     @html.validationmessagefor(model => model.inventorytypechilds[i].inventorytransactionprice)                                 </td>                                 <td>                                     @html.editorfor(model => model.inventorytypechilds[i].inventorytransactionquantity)                                     @html.validationmessagefor(model => model.inventorytypechilds[i].inventorytransactionquantity)                                 </td>                                 <td>                                     @html.editorfor(model => model.inventorytypechilds[i].inventorytransactionremarks)                                     @html.validationmessagefor(model => model.inventorytypechilds[i].inventorytransactionremarks)                                 </td>                                 <td>                                     <input type="submit" value="add" />                                 </td>                             </tr>                         }                     }                 }                 </table>             }         </div>         <p>             <input type="submit" value="in" />         </p>     </fieldset> } 

controller (still rough):

public actionresult inmultipletransaction()         {             viewbag.inventorytypeid = new selectlist(db.inventorytypes, "inventorytypeid", "inventorytypename");             viewbag.supplierid = new selectlist(db.suppliers, "supplierid", "suppliername");             inventorytransactionparent itp = new inventorytransactionparent();             itp.inventorytypechilds = new list<inventorytypechild>();             itp.inventorytypechilds.add(new inventorytypechild()             {              });              return view(itp);         } 

you don't need use partial views in one-to-many relationship. partial views useful if parent , child objects being created @ same time, happens in one-to-one relationship (but then, people use viewmodels). in case, have have parent object created first add many child objects.

this plural sight video way start. there free trial


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -