编辑可变长度列表,ASP.NET MVC 3与样式表 [英] Editing a Variable Length List, ASP.NET MVC 3 Style with Table

查看:77
本文介绍了编辑可变长度列表,ASP.NET MVC 3与样式表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下面史蒂芬·桑德森的博客文章的此处创建项目的编辑和可变长度列表。在他的岗位,他使用的div在列表中显示一个新的项目,但我使用的表。因此,我对每个项目局部视图与渲染各个领域编辑tr标签。现在我的部分观点看起来是这样的:

I am following Steven Sanderson's blog post here to create an editable and variable length list of items. In his post he uses divs to display a new item in the list but I am using a table. Thus, my partial view for each item is rendering a tr tag with the various fields to edit. Right now my partial view looks something like this:

<tr>                
       @using (Html.BeginCollectionItem("LineItems"))
       {             
            <td>        
                @Html.TextBoxFor(m => m.Description)
                @Html.ValidationMessageFor(m => m.Description)                              
            </td>
            <td>
                @Html.TextBoxFor(m => m.Quantity)        
                @Html.ValidationMessageFor(m => m.Quantity)
            </td>
            <td>
                @Html.TextBoxFor(m => m.Amount)          
                @Html.ValidationMessageFor(m => m.Amount)       
            </td>
       }       
</tr>

这实际上是正确呈现在我测试了所有的浏览器,但问题是,这确实会产生无效的HTML,因为它开放tr标签后立即放置一个隐藏的输入标签。

This actually renders correctly on all browsers I have tested but the problem is that this really generates invalid HTML as it places a hidden input tag right after the opening tr tag.

<tr>
   <input type="hidden" name="LineItems.index" .... />
   <td>
      ...
   </td>
   ...
</tr>

有是通过在链接后,说你可以移动使用语句转换成第一标记其他用户评论和它的作品,但我一直没能得到这个使用ASP.NET MVC 3和剃刀工作视图引擎。

There is a comment by another user on the linked post that says you can move the using statement into the first tag and it works but I haven't been able to get this to work using ASP.NET MVC 3 and the Razor view engine.

有没有人有任何想法如何使用由史蒂芬·桑德森psented逻辑$ P $,但得到的第一个TD里面隐藏的索引输入字段,因此不产生无效的HTML?

Does anyone have any idea how to use the logic presented by Steven Sanderson but get the hidden index input field inside the first td so as not to generate invalid HTML?

感谢

推荐答案

有点实验后,我想出了:

After a bit of experimenting I came up with:

<tr>                
   <td>        
   @using (Html.BeginCollectionItem("LineItems"))
   {             
            @Html.TextBoxFor(m => m.Description)
            @Html.ValidationMessageFor(m => m.Description)                              
        @:</td>
        @:<td>
            @Html.TextBoxFor(m => m.Quantity)        
            @Html.ValidationMessageFor(m => m.Quantity)
        @:</td>
        @:<td>
            @Html.TextBoxFor(m => m.Amount)          
            @Html.ValidationMessageFor(m => m.Amount)       
   }       
   </td>
</tr>

这奏效了我。

这篇关于编辑可变长度列表,ASP.NET MVC 3与样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆