MVC一个action对应多个视图的写法

一,如下代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace WebTestDemo.Controllers
{
    public class TestRouteController : Controller
    {
        // GET: TestRoute
        public ActionResult Index(int id=0)
        {
            if (id == 1)
            {
                return View("TRounte");
            }
            else if (id == 2)
            {
                return View("TRounte");
            }
            else
            {
                return View();
            }
        }

        //public ActionResult TRounte()
        //{
        //    return View();
        //}
    }
}

二,视图结构

这里我们不需要添加多个action

 

posted @ 2018-09-20 12:34  叶丶梓轩  阅读(566)  评论(0编辑  收藏  举报