PDA

View Full Version : [CLOSED] Setting Store Datasource - MVC



adelaney
Oct 23, 2012, 2:19 PM
I have a controller which is using the controller extensions and as such, I am using the GetCmp method for a store. After that I am trying to set the store's datasource from a list of a model:




Dim emailData As New List(Of Email)
emailData.Add(New Email() With {.Subject = "Test Email", _
.Sender = sample.CorrespondentInfo.EmailAddress, _
.CarbonCopy = Me.MakeRecipient(sample.BrokerInfo), _
.Body = Me.MakeBody(sample), _
.Recipient = Me.MakeRecipient(sample.Documents(0).Cedent) _
+ Me.MakeRecipient(sample.Documents(0).Reinsurers)})

Me.GetCmp(Of Store)("storeEmail").DataSource = emailData
Me.GetCmp(Of Store)("storeEmail").DataBind()


The controller goes through a lot of rules to get the correct information, but in the end, it just provides string values to the email object. I have inspected the email object, and it is functioning as expected. I have inspected the Me.GetCmp(Of Store)("storeEmail") code and it is getting the correct component. However, after I set the DataSource property and inspect it, the value is "null" -even though I have one item in my list. The result is that nothing is being bound to my store. Is there anything obvious here I am missing on setting the datasource of a store?

Thanks in advance.

Daniil
Oct 23, 2012, 2:30 PM
Hi @adelaney,

Is it all during a DirectEvent?

adelaney
Oct 23, 2012, 2:38 PM
It is currently within a Ajax.BeginForm block.

adelaney
Oct 23, 2012, 4:34 PM
Just an extra bit of info - I don't think I actually have the store. If I inspect this: Me.GetCmp(Of Store)("storeEmail"), I do see an object, but even if I put in a fake ID (e.g. "store123") that I know doesn't exist, I still get an object to inspect in the immediate window. So, how do I know whether the controller really has the "real" component or not? (I would have expected a "nothing" for an invalid ID).

Daniil
Oct 23, 2012, 6:55 PM
It is currently within a Ajax.BeginForm block.

Well, you could just use the Store's DataSource property.

.DataSource(emailData)


Just an extra bit of info - I don't think I actually have the store. If I inspect this: Me.GetCmp(Of Store)("storeEmail"), I do see an object, but even if I put in a fake ID (e.g. "store123") that I know doesn't exist, I still get an object to inspect in the immediate window. So, how do I know whether the controller really has the "real" component or not? (I would have expected a "nothing" for an invalid ID).

Well, X.GetCmp<>() does know nothing about real controls. Generally, Razor engine doesn't operate at all with the "control" term.

This method just creates a proxy class which can be used to generate JavaScript during DirectEvents or DirectMethods which calls controller actions.