zoukankan      html  css  js  c++  java
  • 5-19

    方法一
    //controller public IActionResult list(){ var objects=new List<Object>(); for(int i=0;i<=10;i++){ objects.Add(new Object{Title="xxxx"+i}); } ViewBag.Objects=objects; return view(objects); } //view <ul> @foreach(Object a in(Viewbag.Objects as IEnumeranle<Object>)){ <li>@a.title</li>
    } </ul>

      

    方法二
    //controller
    public IActionResult list(){
      var objects = new List<Object>();
      for(int i=0;i<=10;i++){
        objects.Add(new Object{Title="xxxx"+i});
      }
      viewBag.Objects=objects;
      return View();
    }

    //view
    <ul>
    @foreach(dynamic a ViewBag.Objects){
      <li>@a.Title</li>
      
    }
    <ul/>

    方法三

    //controller

    public IActionResult list(){
      var objects = new List<>(Object);
      for(int i = 0;i<=10;i++){
         objects.Add(new Object{Title="xxxx"+i}); 
      }
      return view(objects);
    }

    //view
    //using MyApplication.Models
    //@model IEnumerable<Object>

    @model IEnumerable<MyApplication.Models.Object>
    <ul>
    @foreach(Object a in model){
    <li>@a.Title</li>
    }


    视图模型(xxxxxViewModels):专门为视图提供信息的模型。不同于MVVM模式中的视图模型。

  • 相关阅读:
    CSS截取字符串
    mysql数据库中列转行
    Html页面操作json串
    mysql批量上传数据
    常见的表单元素选中
    关于Connection must be valid and open.
    百度editor调用【图片上传阿里云】
    百度apistore第三方登陆
    如何提高网页运行性能
    Html页面加回滚
  • 原文地址:https://www.cnblogs.com/dagedan/p/5509668.html
Copyright © 2011-2022 走看看