ASP.NET MVC3表格嵌套输出实现方法

1.控制器

HomeController.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcApplication1.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            List<int> ids = new List<int>();
            for (int i = 0; i <= 100; i += 10)
                ids.Add(i);
            return View(ids);
        }

        public ActionResult Index2(int id)
        {
            List<int> ids = new List<int>();
            for (int i = id + 1; i <= id + 10; i++)
                ids.Add(i);
            return View(ids);
        }
    }
}

2.视图

Index.cshtml:
@model List<int>
@{
    Layout = null;
}

<table>
@foreach (var item in Model)
{
    <tr>
        <td>@item</td>
    </tr>
    <tr>
        <td>@Html.Action("Index2", new { id = @item })</td>
    </tr>
}    
</table>

Index2.cshtml:
@model List<int>

@{
    Layout = null;
}

<table><tr><td>@string.Join(",", Model)</td></tr></table>


评论: 0 | 引用: 0 | 查看次数: 3447
发表评论
登录后再发表评论!