MVC3 Model with collection creating new collection - asp.net-mvc-3

I have a model that contains a collection property as List(). In my view, each of the ChildModel objects is rendered in a table row via it's own Editor Template.
On postback, my model gets bound correcty in that contains a list of ChildModels with the correct about of items originally created in the view, but all the properties of the ChildModel are null, with the exception of the single Editable field.
Based upon this, it appears as if it is creating an entirely new collection of objects, and forgetting all about any values set previously.
I've tried adding the other child object properties to hidden fields, but I still get default values (nulls or zeros) for all properties accept for the one I have created an edit control for. (textbox).
Any thoughts on how to get at a minimum a key field for my item so I can simply update my existing collection?
I found that my hidden field value is in the Request.Form on postback with the Quantity values as well as the values I put in the Hidden fields. I'm not sure why the FormValueProvider isn't parsing those values.

Related

How to hide one2many's field column in tree view based on parent field value in odoo9

I have created a new field in sale order line named as "Price1" and "Price_chk" boolean field in Sale order. The field "Price1" should be invisible in tree view when the field "Price_chk" is False and it should be visible when the field "Price_chk" is True.
You can not hide field conditionally in tree/list view, you can invisible but that should be fixed for all data not conditionally.
You can only set readonly and required (if treeview is editable).
Solution:
You can use two different treeview, for that you need to create two menus and two separate actions, in that action you need to specify view and domain.

How do I link two fields to the same table in ServiceNow?

Forgive my ignorance for the proper terminology, but let me try to explain what I want to happen.
I have two custom fields on the incident table/form. I have created a custom table with 2 columns. I have figured out how to reference the table in one of the fields, allowing me to search the entries. Now I want to link the field selection to the other field via the custom table I made. When I make a selection in field A, I want field B to populate with the other column on the same row Field A pulled from in the first place. How would I do that?
Sounds like you want what's commonly referred to as a "derived field" or a dot-walked field.
You have a reference field which stores the reference to the other table, and want a second field on the form that shows another field on that referenced table. You don't actually need to create a new element, you just need to add a dot-walked form element.
Once you have the reference field added, go to Personalize/Configure the form layout.
In the slushbucket of available fields, you'll notice that reference
fields show up in green text with a little [+] next to them.
Select your reference field and a little button will show up between the two
lists, just above the "Add" button
Click that button and the left-side available fields will show the fields available on that reference field's table.
From here, select that second field that you want to display on your form, and bring it over to the right side where you want it.

Linq2SQL and IQueryable

Still new to LINQ2SQL so please forgive my ignorance ...
I have one user component which includes one Textbox and one button. The component is used as a generic ListOfValue Filter.
The component has one function to set a IQueryable which is passed to a form that is opened when the user clicks a button on the control.
The form consists of a grid (c1flexgrid) which is filled with the data from the IQueryable. There is a bindingsource on the form that gets the IQueryable as datasource.
The user can select inside the grid and after he selected an entry the dialog is closed and the selected row (or better the selected LINQ2SQL object from the row) is passed back to the control.
On this control i want to show one specific field out of that selected object. The name of that field is passed in to the user control as string.
My problem is, i don't know how to get that field data from an "generic" LINQ2SQL object.
In debugger i can see, that the selected object is of a specific enity type (corresponding to the query)
Probably somthing similar to
Workaround for lack of 'nameof' operator in C# for type-safe databinding?
but just the opposit way :)
Any help would be very welcome
I'm assuming in your IQueryable you don't know at design time the type T. If this is correct, you need to use reflection to get the value you want.
var value = typeof(T).GetProperty("MyField").GetValue(instance, null);
Alternatively, cast the instance to a common base type that implements your field.
CommonBase castInstance = (CommonBase)instance;
var value = castInstance.MyField;

How can I set the name attribute when using EditorFor?

I'm writing the partial view for the child collection ('Vehicles') of my model that renders each element in a table row. My model is therefore in the form of
#model IEnumerable<OrderVehicleViewModel>
For modelbinding to work I need the name of each element to be in the form
Vehicles[0].LicenceExpiry
If I use EditorFor then names are generated in the form
item.LicenceExpiry
If I set the HtmlAttributes with a name value it is seemingly ignored, to get around this I have to do
#Html.TextBox("Vehicles[" + i + "].LicenceExpiry", item.LicenceExpiry)
The problem is then, I lose all the formatting as TextBox doesn't adhere to the DisplayFormat attribute on my model and it means I have to manually build SelectLists for simple boolen properties whereas the default template used by EditorFor does it for me. What is the best way to achieve this?

Setting a default selection for an NSPopupButton?

Is it possible to set a default selection on an NSPopupButton? I have one that allows the user to select the type of server they want to set up, but since an NSPopupButton always shows the first item, they may ignore it if that's the type they want. However, even though that item is being displayed, calling -selectedItem returns (null). Everything works fine if the user picks an item from the menu first.
The Button's content and contentValues are bound to the same Array Controller, which in turn is bound to the keys property of an NSDictionary. I've tried binding the selectedIndex to a variable in the controller and updating that in code, but it has no effect. (I may just be binding it wrong...) How can I select the first item by default?
Thanks in advance!
SphereCat1
When using Bindings, you don't need to and shouldn't get any model info—neither the model itself nor selection state—from the views directly. Talk to the controller that owns the model and the selected indexes.
Note that “index” doesn't have any meaning for an NSDictionary, and keys is not a property of an NSDictionary. (Indeed, I would not be surprised if you were to get an exception because your dictionary does not have an object for the key “keys” in it.) It is a method, and not the accessor kind, so while you can ask the dictionary for the value of that method using Key-Value Coding, you should not.
What you should do is make model objects representing the server types, and hold an array of those, and bind the array controller's content to the property whose value is that array. Bind the pop-up button's contentValues to a name property of your model objects, which should hold the localized name of each server type.

Resources