views:

38

answers:

2
<table class="data-table">
    <tr>

        <th style="width: 200px;">
            DescriptionDescription <%--in this case <td> is resized--%>
        </th>
    </tr>
<% foreach (var item in Model) { %>

    <tr>
        <td style="width: 200px;">
            <%= Html.Encode(item.Description) %>
        </td>
    </tr>
  <% } %>
</table>

browser html:

    <table class="data-table"> 
        <tr> 
          <th style="width: 200px;"> 
            Description
          </th> 
        </tr> 
        <tr> 
          <td > 
           This is description
          </td>    
    </tr> 
   </table> 

Why this td size is not to apply on View page? In Design view on VS 2008 td size is applied, but after run project in my browser not have specified size

+1  A: 

I tried the following code and it renders as expected:

<table class="data-table">
    <tr>

        <th style="width: 200px;">
            Description
        </th>
    </tr>
<% foreach (var item in Model) { %>

    <tr>
        <td style="width: 200px;">
            <%= Html.Encode(item.Description) %>
        </td>
    </tr>
<% } %>   
</table>  

Which outputs the following HTML:

<table class="data-table">
    <tr>

        <th style="width: 200px;">
            Description
        </th>
    </tr>
    <tr>
        <td style="width: 200px;">
            1
        </td>
    </tr>
</table>  

If this is the code you actually have and it's not rendering the style tag then I've no idea why it's not working. As I've shown above, what you have provided in your question works perfectly with the brace correct positioned (even though the brace positioning should just cause bad HTML instead of removing a style element...).

EDIT:

Sounds more to me like you're not looking at the correct website, or you're not closing and reopening the browser source window. The code itself doesn't appear to have any problems, unless of course the code you've provided isn't for the view output you're looking at.

GenericTypeTea
Yes, I have this code and it is not rendering style tag
Ognjen
check the code, I update it
Ognjen
Your 'updated' code is still wrong. The brace is still in the wrong position.
GenericTypeTea
now is in the right place, but problem is still there
Ognjen
Might sound like a daft question, but are you definitely looking at the correct address for the website in question? Are you looking at a published site instead of running the site in debug mode? What's the URL in your browser window?
GenericTypeTea
http://localhost:1493/ImportXML
Ognjen
I'm out of ideas. The code works perfectly. Good luck.
GenericTypeTea
Tnx, I am using asp.net mvc maybe it creates a problem
Ognjen
My example was also created in MVC. There's no problem with the code.
GenericTypeTea
A: 

Not sure why the style attribute is removed. But as an alternative you could use css:

<style>
table.data-table td{width:200px;background-color:red;}
</style>
<table class="data-table"> 
        <tr> 
          <th style="width: 200px;"> 
            Description
          </th> 
        </tr> 
        <tr> 
          <td > 
           This is description
          </td>    
    </tr> 
</table> 
rdkleine
Your style render all tables except this one
Ognjen
Interesting, when I open the HTML in IE it show a red tablecell. You say it renders all tables, are those tables decorated with class=data-table?
rdkleine
yes, all tables is decorated with class="data-table", I am using chrome and mozzila firefox
Ognjen