using DisplayFor in a table

I am trying to use DisplayFor in a table like so:
<table>
   <tr>
      <td>@html.LabelFor(model => model.name)</td>
      <td>@html.DisplayFor(model => model.name)</td>
      <td>@html.LabelFor(model => model.street)</td>
      <td>@html.DisplayFor(model => model.street)</td>
   </tr>
</table>

BUT, it displays the labels together and then the values!  I don't understand!
dan hendersonAsked:
Who is Participating?
 
Miguel OzSoftware EngineerCommented:
Use text-* classes from bootstrap.
<div class="row">
	<div class="col-xs-3">
		@html.LabelFor(model => model.name)
	</div>
	<div class="col-xs-3 text-center">
		@html.DisplayFor(model => model.name)
	</div>
	<div class="col-xs-3">
		@html.LabelFor(model => model.street)
	</div>
	<div class="col-xs-3 text-center">
		@html.DisplayFor(model => model.street)
	</div>
</div>

Open in new window


All display code will display centred (assuming they are text of course)
P.S. I f more help needed please post  a screenshot of what you have vs what you would like to see (Use MS Excel to prototype - specify which alignment each cell must have)
0
 
Miguel OzSoftware EngineerCommented:
Rather than table use bootstrap grid that comes by default with an asp.net mvc project:

<div class="row">
	<div class="col-xs-3">
		@html.LabelFor(model => model.name)
	</div>
	<div class="col-xs-3">
		@html.DisplayFor(model => model.name)
	</div>
	<div class="col-xs-3">
		@html.LabelFor(model => model.street)
	</div>
	<div class="col-xs-3">
		@html.DisplayFor(model => model.street)
	</div>
</div>

Open in new window

P.S. I f more help needed please post VS/asp.net mvc version as well as a screenshot of what you have vs what you would like to see (Use excel to prototype)
0
 
dan hendersonAuthor Commented:
Your post is exactly what I started with ... in fact, that is how my Edit view is contructed.  But when I used the @Html.DisplayFor() it put the displayed values at the end of the line with all the LabelFor()'s at the start of the line:
label, label, displayfor, displayfor.  That is why I tried using a table, so the alignment would be correct (although it isn't).

I am using VS 2017 and MVC 5.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.