Extension ... And Fluent ? Behavior

S

Shapper

Hello,

I have an extension as follows:

public static HtmlString Menu(this HtmlHelper html) { }

But I would like being able to use it as follows:

@(Html.Menu().Name("menu")
.Items(menu =>
menu.Add().Text("Home").Action("Index", "Home");
menu.Add().Text("Company").Items(item => {
item.Add().Text("About Us").Action("AboutUs", "Company");
item.Add().Text("Contact").Action("Contact", "Company");
});
}))

Then I need to build a string with the value in Name and with Items and Sub-Items and their Text and Action properties.

I am not sure how can this be done.

I just know that it is possible because I saw a company that does this but it is not open source so I am not able to look at it.

Any idea of how can I do this?
 
A

Arne Vajhøj

I have an extension as follows:

public static HtmlString Menu(this HtmlHelper html) { }

But I would like being able to use it as follows:

@(Html.Menu().Name("menu")
.Items(menu =>
menu.Add().Text("Home").Action("Index", "Home");
menu.Add().Text("Company").Items(item => {
item.Add().Text("About Us").Action("AboutUs", "Company");
item.Add().Text("Contact").Action("Contact", "Company");
});
}))

Then I need to build a string with the value in Name and with Items and Sub-Items and their Text and Action properties.

I am not sure how can this be done.

I just know that it is possible because I saw a company that does this but it is not open source so I am not able to look at it.

Any idea of how can I do this?

You define the necessary methods.

It is difficult to say much more without knowing about
the classes you are using and the context.

I would assume Html is am instance HtmlHelper. But what
is HtmlString? System.Web.HtmlString does not have a member
Name.

Arne
 
S

Shapper

On 7/6/2012 3:40 PM, Shapper wrote:
> I have an extension as follows:
>
> public static HtmlString Menu(this HtmlHelper html) { }
>
> But I would like being able to use it as follows:
>
> @(Html.Menu().Name("menu")
> .Items(menu =>
> menu.Add().Text("Home").Action("Index", "Home");
> menu.Add().Text("Company").Items(item => {
> item.Add().Text("About Us").Action("AboutUs", "Company");
> item.Add().Text("Contact").Action("Contact", "Company");
> });
> }))
>
> Then I need to build a string with the value in Name and with Items and Sub-Items and their Text and Action properties.
>
> I am not sure how can this be done.
>
> I just know that it is possible because I saw a company that does this but it is not open source so I am not able to look at it.
>
> Any idea of how can I do this?

You define the necessary methods.

It is difficult to say much more without knowing about
the classes you are using and the context.

I would assume Html is am instance HtmlHelper. But what
is HtmlString? System.Web.HtmlString does not have a member
Name.

Arne

Hello,

Yes, System.Web.HtmlString does not have a member name.

Basically, I am trying to replicate the way this component works:

http://demos.telerik.com/aspnet-mvc/menu

Please, click on View tab to see the code of how it is used.

I am trying to figure how that is done.

Thank You,
Miguel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top