Hi,
I'm trying to understand how to bind an action from the Db to the kendo menu.
in all the demos I saw there is and Item.add().text().action("action","controller");
but if I bind to Db then I have:
Item.Text = "Some Text";
how should I attach the action method to the menu? (what should be the right side of the item.Action = ?)
I would also like your opinion as to the way to store it in the Db (if there is any best practice regrding this matter).
thank you
I'm trying to understand how to bind an action from the Db to the kendo menu.
in all the demos I saw there is and Item.add().text().action("action","controller");
but if I bind to Db then I have:
Item.Text = "Some Text";
how should I attach the action method to the menu? (what should be the right side of the item.Action = ?)
I would also like your opinion as to the way to store it in the Db (if there is any best practice regrding this matter).
thank you
6 Answers, 1 is accepted
0
Hi,
or the Action method:
Regards,
Daniel
Telerik
You can either use the ActionName and ControllerName properties:
item.ActionName =
"Action"
;
item.ControllerName =
"Controller"
;
item.Action(
"Action"
,
"Controller"
,
null
);
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
ShareDocs
Top achievements
Rank 1
answered on 06 Jun 2013, 04:22 PM
Hi,
I tried it but the menu doesnt responds and i don't get anything on fiddler too...
is there anything to pay attention when using actions? (I don't get an error, just a menu that does not redirect me :( )
UPDATE:
I managed to get it to work.
I've set the parent mapping action and controller and it's now working (why I can't set it through the childs if the childs is what I want to get the action?)
I tried it but the menu doesnt responds and i don't get anything on fiddler too...
is there anything to pay attention when using actions? (I don't get an error, just a menu that does not redirect me :( )
UPDATE:
I managed to get it to work.
I've set the parent mapping action and controller and it's now working (why I can't set it through the childs if the childs is what I want to get the action?)
0
Hello Lior,
Daniel
Telerik
I am not sure what could be causing the described behavior. Could you provide the code you are using?
Regards,Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
ShareDocs
Top achievements
Rank 1
answered on 10 Jun 2013, 04:05 PM
what part of the code do you want?
this is the view
this is the Key_MenuItems entity:
this is the layout which contains the calling to the controller method that brings the partialView:
Hope you'll find the reason...
this is the view
@model IEnumerable<
EladFI.Domain.Entities.Key_MenuItems
>
@(Html.Kendo().Menu()
.Name("Menu") //The name of the menu is mandatory. It specifies the "id" attribute of the widget.
.BindTo(Model , mappings =>
{
mappings.For<
EladFI.Domain.Entities.Key_MenuItems
>(binding => binding //define first level of menu
.ItemDataBound((item, category) => //define mapping between menu item properties and the model properties
{
item.Text = category.Menu_Title;
item.ImageUrl = category.Menu_Image ?? "";
if (category.Action != null)
{
item.ActionName = category.Action.Split('|')[0];
item.ControllerName = category.Action.Split('|')[1];
}
})
.Children(category => category.ChildMenuItems.Where(x => x.Is_Active && x.Action !=null))); //define which property of the model contains the children
mappings.For<
EladFI.Domain.Entities.Key_MenuItems
>(binding => binding
.ItemDataBound((item, product) =>
{
item.Text = product.Menu_Title;
}));
})
)
this is the Key_MenuItems entity:
public
class
Key_MenuItems
{
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity), Key()]
public
int
ID {
get
;
set
; }
public
string
Menu_Title {
get
;
set
; }
public
int
? Parent_ID {
get
;
set
; }
public
string
Action {
get
;
set
; }
public
int
Menu_Order {
get
;
set
; }
public
bool
Is_Active {
get
;
set
; }
public
string
Menu_Image {
get
;
set
; }
public
bool
QA_Only {
get
;
set
; }
public
bool
Is_Blank {
get
;
set
; }
public
virtual
Key_MenuItems Parent {
get
;
set
; }
public
virtual
ICollection<Key_MenuItems> ChildMenuItems {
get
;
set
; }
}
this is the layout which contains the calling to the controller method that brings the partialView:
<
div
class
=
"float-right"
>
@{Html.RenderAction("Menu", "Menu");}
</
div
>
Hope you'll find the reason...
0
Hello Lior,
Daniel
Telerik
The same type is specified for both mappings. The Menu will automatically bind the children on all levels for homogeneous data and so the second mapping will not be taken into account. If the action should not be used for the top level items then you should the approach that it seems you are already using and set the action and controller configuration only when needed.
Regards,Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Accepted
ShareDocs
Top achievements
Rank 1
answered on 12 Jun 2013, 07:20 PM
I understand now,
thank you
thank you