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

[Solved] Foreign key Data binding in the Dropdownlist

0 Answers 53 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
MAQ MA
Top achievements
Rank 1
MAQ MA asked on 29 Mar 2012, 03:01 PM
Hi

I want to know more about foreign key data binding.
Let me give you example
Imagine that you have two tables Customer and Order. In Order table I have CustomerId as foreignkey which points to primary key in the customer table.

Now I am developing a new order form in which I want to give Customers DropDownList
If I go for standard MVC helper I am able to get the CustomerId value in the Action method (Create). But when I used Telerik extension though the data gets binded in the dropdownlist but on submit I am not getting value of the customer id
@Html.Telerik().DropDownList().Name("Customers").BindTo(new SelectList(ViewBag.Cats,"Id","Description"))
If I use Telerik DropDownlistfor then I am not able to bind the dropdown
@Html.Telerik().DropDownListFor(model=>model.CustId)
If i use standard helper method of Mvc then everything works as expected and I can save the record in the table
@Html.DropDownListFor(model => model.CatId, ViewBag.Cats as SelectList)

Please advise if I am doing something wrong.

Thanks
Tags
General Discussions
Asked by
MAQ MA
Top achievements
Rank 1
Share this question
or