木子屋 Dnawo's BLOG

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

👤 dnawo 📅 2012-12-31 👁 4359 👍 0 💬 0 🔄 本站原创
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>[color=Red]@Html.Action("Index2", new { id = @item })[/color]</td>
    </tr>
}    
</table>

Index2.cshtml:
@model List<int>

@{
    Layout = null;
}

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

评论(0)

暂无评论。

计算题
评论需审核通过后显示
← 上一篇 国家统计局县及县以上行政区划导入SQL Server步骤 下一篇 → ASP.NET MVC3中Html.Partial和Html.R…