0

I'm looping through rows and trying to make use of my DataTable Model.

    <td>@Html.DisplayFor(d => d.Rows[i].ItemArray[j])</td> 

Im passing in five values per Row, per ItemArray, the first two are strings, the other three are strings but are either "True" or "False". I thought DisplayFor would detect this and create a CheckBox for the boolean strings.

I get five strings. Do I need additional params?

2
  • No, you need to use the correct data types. Commented Sep 26, 2012 at 14:38
  • @podiluska - I tried casting it as bool but I get template errors, perhaps I need to re jig the model before posting it to the View? Commented Sep 26, 2012 at 14:43

1 Answer 1

3

I thought DisplayFor would detect this and create a CheckBox for the boolean strings.

DisplayFor never creates any input fields, unless of course you write a custom template that will generate a checkbox (but I wouldn't do that). That's the whole point of display templates. It's for displaying only.

If you want to generate input fields use an editor template (Html.EditorFor).

Take a look at how the default templates look like.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I'm confusing myself and the issue because the first two strings I only want to display but of course eventually I'll want my user to edit the checkboxes. Thanks, I'll re-think the model!!

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.