This is a migrated thread and some comments may be shown as answers.

Model Binding Signatures

4 Answers 45 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Holger
Top achievements
Rank 1
Holger asked on 25 Oct 2015, 10:14 AM

The documentation here:

http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/data-binding/model-binding-and-strongly-typed-data-controls-support

gives a Signature for Modelbinding Delete like this.

 

public void DeleteProduct(int ProductID

 

)


I tried to implement it, but first I get an ASP.NET error, saying the Method has to allow Reference-Types, because the Grid wants to pass NULL to it.
I changed it to (int? ProductID), the error disappeared,  but still the key ID null, although I have specified the

DataKeyNames="ProductID"

Also: 

SelectMethod="Select" DeleteMethod="Delete" UpdateMethod ="Update" InsertMethod ="Insert"

Attributes in the RadGrid Tag, sometimes in the MasterTableView Tag, does this make a difference ?
The question is not just on Delete, Update behaves in the same way, saying it hast to be an "int?"


May be I'm mixing up different binding models here ?
Why is Delete(int ProductId) not working ?

Is thery any Switch to say "I want to do Model binding" ?

 
 
 
 

4 Answers, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 28 Oct 2015, 10:27 AM
Hello Holger,

If the field is added to the DataKeyNames collection it should be passed to the Update method. However, it would be hard to pinpoint what is causing the behavior on your end without further investigation.

Would you share your markup with the related code-behind and also the model? This will enable us to have better understanding of your setup. Moreover we would be able to examine the code and look for possible issues.

Regards,
Viktor Tachev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Holger
Top achievements
Rank 1
answered on 28 Oct 2015, 05:18 PM

Hi, I have found the problem myself/with a friend.
It's  badly or not at all documented.

Model is as follows:

   

public class Artist
{
    [Key()]
    public int AID { get; set; }
    [Required()]
     public string Name { get; set; }
}
 
class Model : DbContext
{
    public Model() : base("name=CBPString")
    {
    }
    public DbSet<Artist> Artists { get; set; }
}

Now, then providing an UpdateMethod like:

public void Update(int id)

You get an error "this method cannot be called with non-nullable types"
In effect, I turned the int to int?, run it again, the call worked, but id=null, although 
<MasterTableView .... DataKeyNames="AID">
was specified.

So this was just to clarify the topic above.

The solution is: The parameter names, of the Update Methods have to match.
with
public void Update(int AID)
is working.

It's  very unusual to a programmer, that the names of local parameters have influence to a procedure call.
Usually, only the signature of a method is checked. So Update(int id) and Update(int AID) is completly equivalent.
Teleriks implementation is making too thorough checks,
and I haven't found any documentation, pointing this extraordinary thing out.

On your link provided, there is a ​line
"Where the “ProductID” is one of the fields set as DataKeyNames of the corresponding bound control."
But this had never ever gave me the idea that in this line
context.Products.Where(p => p.ProductID == ProductID).First();
You really mean, both occurrences of ProductID have literally to match, the term of both sides of == have to be the same.


 


0
Holger
Top achievements
Rank 1
answered on 28 Oct 2015, 05:25 PM

By the way:

The documentation has a bug, the InsertMethod is not specified at all  or completly corrupted.

The InsertMethod can have following signatures:
Deleting
In order to have deleting ..


 http://docs.telerik.com/devtools/aspnet-ajax/controls/grid/data-binding/model-binding-and-strongly-typed-data-controls-support#model-binding-selecting-data-paging-and-sorting

0
Viktor Tachev
Telerik team
answered on 02 Nov 2015, 12:56 PM
Hello Holger,

I am glad that you have the issue resolved.

Thank you for pointing the missing information in the documentation. We will update it as soon as possible.

If you have additional queries regarding our controls do not hesitate to contact us again.

Regards,
Viktor Tachev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Holger
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Holger
Top achievements
Rank 1
Share this question
or