Note that there are some explanatory texts on larger screens.

plurals
  1. POWebForms Model Binding: Automatically map updated values to Item
    primarykey
    data
    text
    <p>I'm currently working on a little dummy application to get my head around the new (awesome) model binding in WebForms. I've succesfully listed data both in a ListView and a FormView, however I'm stuck on updating the data.</p> <p>I have a very simple FormView control:</p> <pre><code>&lt;asp:FormView runat="server" ID="formViewOrderDetail" ItemType="ModelBindingDummy.Models.Order" DataKeyNames="Id" SelectMethod="GetOrder" UpdateMethod="UpdateOrder"&gt; &lt;ItemTemplate&gt; &lt;p&gt;Supplier Order Number: &lt;%#: Item.SupplierOrderNumber %&gt;&lt;/p&gt; &lt;asp:LinkButton Text="Edit" runat="server" ID="linkEdit" CommandName="Edit" /&gt; &lt;/ItemTemplate&gt; &lt;EditItemTemplate&gt; &lt;p&gt;Supplier Order Number: &lt;asp:TextBox runat="server" ID="SupplierOrderNumber" Text='&lt;%#: Item.SupplierOrderNumber %&gt;' /&gt; &lt;/p&gt; &lt;asp:LinkButton Text="Cancel" runat="server" CommandName="Cancel" /&gt; &lt;asp:LinkButton Text="Save" runat="server" CommandName="Update" /&gt; &lt;/EditItemTemplate&gt; &lt;/asp:FormView&gt; </code></pre> <p>My <code>UpdateOrder</code> method looks like this:</p> <pre><code>public void UpdateOrder(int id) { ModelBindingDummy.Models.Order item = GetOrder(id); if (item == null) { ModelState.AddModelError("", String.Format("Item with id {0} was not found", id)); return; } TryUpdateModel(item); //All data in the app is in-memory, so no need to actually update //the item as it is only a reference } </code></pre> <p>Now my problem is that the TryUpdateModel doesn't work. It simply ignores the value in the TextBox <code>SupplierOrderNumber</code></p> <p>I've tried adding a parameter to the update method, <code>[Control] string supplierOrderNumber</code>, and while that works, I'd really like to see a way to automatically map that value.</p> <p>I've also seen solutions using the <code>&lt;asp:DynamicEntity /&gt;</code> control, but that seems somewhat overkill.</p> <p>So my question is: Is it possible to get the <code>TryUpdateModel</code> method to map the TextBox value, or do I need to go all the way with the <code>DynamicEntities</code> control, or are there any other fancy solutions?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload