2

I have Html helper method, creating a check box along with some text, I pass.

@Html.CheckBoxFor(x => x.SomeProperty,@<text> <ul> <li> </li> </ul>           </text>}))


public static MvcHtmlString CheckBoxFor<TModel, TProperty>(this HtmlHelper<TModel> helper, Expression<Func<TModel, bool>> expression, ?? )
    {
        var chkBox = helper.CheckBoxFor(expression).ToString();

        return MvcHtmlString.Create(string.Format("<li>{0}</li><div>{1}</div>", chkBox, ??);
    }

What would be the signature of my method then. Some lambda/expression or something.

Help will be appreciated.

Regards

Parminder

1
  • Define it as an object, run it, and see what the runtime gives you as its type. Commented Oct 28, 2011 at 0:11

2 Answers 2

6

I would recommend you looking at templated razor delegates. So in your case the helper might look something along the lines of:

public static MvcHtmlString CheckBoxFor<TModel>(
    this HtmlHelper<TModel> helper, 
    Expression<Func<TModel, bool>> expression,
    Func<object, HelperResult> template)
{
    var chkBox = helper.CheckBoxFor(expression).ToHtmlString();
    return MvcHtmlString.Create(
        string.Format("<li>{0}</li><div>{1}</div>", chkBox, template(null))
    );
}

and in the view:

@model MyViewModel
@using (Html.BeginForm())
{
    @Html.CheckBoxFor(
        x => x.SomeProperty,
        @<text><ul><li></li></ul></text>
    )
    <input type="submit" value="OK" />
}
Sign up to request clarification or add additional context in comments.

Comments

0

Just string. It's going into string.Format, so that gives you a hint.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.