Link to home
Start Free TrialLog in
Avatar of dan henderson
dan hendersonFlag for United States of America

asked on

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!
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

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)
Avatar of dan henderson

ASKER

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.
ASKER CERTIFIED SOLUTION
Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial