【问题标题】:Can we use Repeater control in Razor MVC3? if yes then how?我们可以在 Razor MVC3 中使用中继器控件吗?如果是,那怎么办?
【发布时间】:2014-07-29 09:22:37
【问题描述】:

我想在 MVC3 razor 中使用中继器控件。 有一个表,其中表的中间部分发生变化,而上部分和下部分对于所有表保持相同。

这是发票的一般要求。 我怎么能这样做使用中继器。 如果有人有其他方法,我也可以尝试。

【问题讨论】:

  • 如果需要更多帮助,请评论....
  • 我已经在剃刀视图中完成了这一切。在循环中使用条件。谢谢你尝试
  • 对此有更好的答案:[mvc 3 等效于 函数][1] [1]:stackoverflow.com/a/6754066/857512

标签: asp.net-mvc-3 asp.net-mvc-4 razor user-controls repeater


【解决方案1】:

答案 1:

不..您不能在asp.net mvc中使用服务器端控件,您只能使用html标签或html助手,为了实现中继器控制功能,您必须使用foreach循环,如下所示:

foreach(var item in Model.List)
{
   <img src='@Url.Content("~/controller/action/" + item)' />
}

或者你也可以使用:

You can use @Html.EditorFor() or DisplayFor with an Editor/Display Template.

答案2(完整示例):

物品类:

public class Items
{
     public int Id { get; set; }
     public string Name { get; set; }
     public List<Items> Itemlst { get; set; }
}

控制器:

public ActionResult List()
{
     Items itemobj = new Items();
     itemobj.Itemlst = //bind list of items here

     return View(itemobj);
}

在我看来,我会有以下几点:

<table>

@foreach(var item in Model.Itemlst)
{
     <tr>
          <td>Items Name:</td>
          <td>@item.Name</td>
     </tr>
}

</table>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-29
    • 1970-01-01
    • 2018-01-01
    • 1970-01-01
    • 2020-03-22
    相关资源
    最近更新 更多