0

I'm adding in the object htmlAttributes parameter and getting an error :

"Error 41 Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access"

Response.Write(Html.CheckBox("chkStatus", item.Value) + " " + item.Text + "<br />");
Response.Write(Html.CheckBox("chkStatus", item.Value,new {checked=true}) + " " + item.Text + "<br />");

I get the error when i try to add the "new {checked=true} part.

Cannot find an example of setting parameter in c# code online, cheers

1 Answer 1

2

I think checked is a keyword. Try putting an @ in front:

new { @checked = true }
Sign up to request clarification or add additional context in comments.

5 Comments

It builds ok with :Response.Write("&nbsp&nbsp" + Html.CheckBox("chkStatus_" + item.Value, item.Value, new { @checked = "true" }) + " " + item.Text + "<br />");
but I get error runtime of : CS1928: 'System.Web.Mvc.HtmlHelper<Lms.Web.Models.FormViewModels.SiteFormViewModel>' does not contain a definition for 'CheckBox' and the best extension method overload 'System.Web.Mvc.Html.InputExtensions.CheckBox(System.Web.Mvc.HtmlHelper, string, bool, object)' has some invalid arguments
Its still not happy with the syntax for the parameter, i'm missing something, cannot figure it
What is the type of item.Value? - it should be bool.
AHH thanks - an oversight on my part, I never even needed the HTML attribute parameter, i just set a true or false for 2nd param and no 3rd oaram, cheers

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.