How to use a partial view to add rows to a table defined in the main view

StackTrace

I have the below table definition in my MVC 3 main view.

 <table id="myDynamicTable" class="myClass" >
            <thead>
                <tr id="uploadrow_0">
                    <th style="white-space: nowrap;display: inline;width: 5px; text-align: left " >
                        Number
                    </th>
                    <th style="white-space: nowrap;display: inline;width: 120px; text-align: left ">
                        Unit
                    </th>
                    <th style="white-space: nowrap;display: inline;text-align: left ">
                        Type
                    </th>
                    <th  style="white-space: nowrap;display: inline;width: 90px; text-align: left ">
                        Date
                    </th>
                    <th style="white-space: nowrap;display: inline;width: 351px; text-align: left ">
                        Action
                    </th>
                    <th style="white-space: nowrap;display: inline;width: 300px; text-align: left ">
                        Comment
                    </th>
                </tr>
            </thead>
            <tbody>
                          @if (Model.ProductDetails.Count > 0)
                          {
                              foreach (var item in Model.ProductDetails)
                              {
                                  @Html.Partial("ProductDetailsPartial", item);
                              }
                          }
                          else
                          {
                              ProductDetailsViewModel item = new ProductDetailsViewModel();
                              item.Types = ViewBag.TypeList;
                              item.Unit = ViewBag.UnitList;
                              item.Number = 1;
                              @Html.Partial("ProductDetailsPartial", item);
                          }

            </tbody>
        </table>

I'm adding rows dynamically to the above table but each row that i add is being generated from a partial view.

Below is my partial view definition

    @model ProductDetailsViewModel
        <tr>
        @using (Html.BeginCollectionItem("item"))
        {
            <td class="autoGenNumber" style="width: 5px" >
                @if (Model == null)
                {
                    ProductDetailsViewModel item = new ProductDetailsViewModel();
                    item.Types = ViewBag.TypeList;
                    item.Unit = ViewBag.UnitList;
                    item.Number = 1;
                   @Html.LabelFor(x => Model.Number, Model.Number.ToString(), new { style = "width: 10px;", @class = "autoGenNumber" })
                }  
            </td>
            <td class="tdUnit">
                @Html.TextBox("Unit", Model.Unit, new { id = "Unit", style = "width:120px; padding: 0px;", @class = "txtUnit" })    
            </td>
            <td class="tdBorder">
                @Html.DropDownListFor(model => model.TypeId, new SelectList(Model.Types, "Value", "Text", Model.TypeId), "[--Select--]", new { @id = "ddlType", style = "width:20px; padding: 0px;", @class = "ddlType" })
            </td>
            <td class="tdBorder">
                @if (Model.Date.ToShortDateString().Contains("1/1/0001"))
                {
                    <input type="text" name="Model.Date" value="@DateTime.Today.ToShortDateString()"  class="txtDate" readonly = "readonly" style = "width: 90px; padding: 0px;" />
                }
                else
                {
                    <input type="text" name="Model.Date" value="@Model.Date.ToShortDateString()"  class="txtDate" readonly = "readonly" style = "width: 90px; padding: 0px;" />
                }
            </td>
            <td class="tdBorder">
              @Html.DropDownListFor(model => model.UnitId, new SelectList(Model.Unit, "Value", "Text", Model.UnitId), "[--Select--]", new { @id = "ddlUnit", style = "width:351px;", @class = "ddlUnit" })
            </td>
            <td class="tdBorder">
                @Html.TextBoxFor(x => Model.comment, new { id = "Comment", @class = "Comment RestrictCharacters", style = "width:300px;" })
            </td>
        } 
 </tr>

The table lay out is coming correctly in IE 8 & above but in chrome and Firefox the Row columns are not properly aligned with the table column headers.

How can i render my partial view as a valid table row in my main view's </tbody> </tbody> element

Below is the screenshot of how my table is appearing in IE (correct layout)

enter image description here

And below is the incorrect lay out in chrome

enter image description here

lukbl

Probably display: inline; on headers is causing this kind of effect.

Normally table cells have display:table-cell;.

Your table headers should look something like:

<th style="white-space: nowrap;width: 120px; text-align: left ">
   Unit
</th>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to use a partial view to add rows to a table defined in the main view

From Dev

How to use Partial View?

From Dev

How to use Partial View?

From Dev

how to add a navigation controller to a view that is not the main view?

From Dev

How to render partial view with in Main view on link clicking in MVC..?

From Dev

How can I refresh partial view and the main view at the same time?

From Dev

How to keep partial view from overlapping content on main view page

From Dev

How can I refresh partial view and the main view at the same time?

From Dev

Add CSS to a View or Partial View

From Dev

How to add a partial view inside a DevExpress navbar

From Dev

How to expand/collapse html table with partial view?

From Dev

How to expand/collapse html table with partial view?

From Dev

Populating table in a partial view

From Dev

Populating table in a partial view

From Dev

Table in partial view not rendering

From Dev

Can I use Javascript (with @ syntax) from partial into the main view?

From Dev

Razor. How to use partial view with IQueryable?

From Dev

MVC Partial View is not rendering correctly in main View

From Dev

Load partial view in main view on click

From Dev

Loading partial view into the main view AngularJS

From Dev

Load partial view after main view

From Dev

MVC Partial View is not rendering correctly in main View

From Dev

Replacing contents of main view with partial view

From Dev

How can I refresh a partial view on the main index page on a submit from a separate partial view modal

From Dev

How to add subview inside main view in Swift

From Dev

how to use a defined view in Sencha Touch

From Dev

How to render partial view?

From Dev

Add action filter to partial view

From Dev

how to show rows as column in mysql view table

Related Related

  1. 1

    How to use a partial view to add rows to a table defined in the main view

  2. 2

    How to use Partial View?

  3. 3

    How to use Partial View?

  4. 4

    how to add a navigation controller to a view that is not the main view?

  5. 5

    How to render partial view with in Main view on link clicking in MVC..?

  6. 6

    How can I refresh partial view and the main view at the same time?

  7. 7

    How to keep partial view from overlapping content on main view page

  8. 8

    How can I refresh partial view and the main view at the same time?

  9. 9

    Add CSS to a View or Partial View

  10. 10

    How to add a partial view inside a DevExpress navbar

  11. 11

    How to expand/collapse html table with partial view?

  12. 12

    How to expand/collapse html table with partial view?

  13. 13

    Populating table in a partial view

  14. 14

    Populating table in a partial view

  15. 15

    Table in partial view not rendering

  16. 16

    Can I use Javascript (with @ syntax) from partial into the main view?

  17. 17

    Razor. How to use partial view with IQueryable?

  18. 18

    MVC Partial View is not rendering correctly in main View

  19. 19

    Load partial view in main view on click

  20. 20

    Loading partial view into the main view AngularJS

  21. 21

    Load partial view after main view

  22. 22

    MVC Partial View is not rendering correctly in main View

  23. 23

    Replacing contents of main view with partial view

  24. 24

    How can I refresh a partial view on the main index page on a submit from a separate partial view modal

  25. 25

    How to add subview inside main view in Swift

  26. 26

    how to use a defined view in Sencha Touch

  27. 27

    How to render partial view?

  28. 28

    Add action filter to partial view

  29. 29

    how to show rows as column in mysql view table

HotTag

Archive