views:

20

answers:

1

I'll give a very simple example:

at the moment I have to write like this:

<% Html.RenderPartial("hello", new HelloInput { Name = "Jimmy" } ); %>

I would like to be able to like this:

<%=Html.Hello("Jimmy") %>

So I would like to know how create this helper:

public static string Hello(this HtmlHelper helper, string name)
{
    return the result of rendering partial view "hello" with HelloInput{ Name = name };
}
+2  A: 

Partial is the <%= version of RenderPartial:

public static string Hello(this HtmlHelper helper, string name)
{
    return helper.Partial("hello", new HelloInput { Name = name } );
}
Kirk Woll
You may replace `new HelloInput { Name = "Jimmy" }` by `new HelloInput { Name = name }` otherwise all people are named Jimmy ;)
Dave
@Dave, thanks, good catch.
Kirk Woll