// Controller 示例代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MyMvcApplication.Controllers
{
    public class HomeController : Controller
    {
        // GET: Home
        public ActionResult Index()
        {
            // 返回视图
            return View();
        }
        // GET: Home/Details/5
        public ActionResult Details(int id)
        {
            // 根据ID获取详细信息并返回视图
            ViewBag.Id = id;
            return View();
        }
    }
}
// View 示例代码 (Index.cshtml)
@{
    ViewBag.Title = "Home Page";
}
<h2>Welcome to the Home Page</h2>
<!-- 这里可以添加更多的HTML和Razor语法来显示数据 -->
<!-- 调用Action链接 -->
<p>@Html.ActionLink("Go to Details", "Details", new { id = 1 })</p>Controller:
HomeController 是一个控制器类,继承自 Controller 类。Index 方法是默认的Action方法,返回一个视图。Details 方法接收一个参数 id,并将该参数传递给视图。View:
Index.cshtml 是一个视图文件,使用 Razor 语法来生成 HTML。@Html.ActionLink 用于生成一个超链接,点击后会调用 Details Action 并传递参数 id。MVC 框架:
上一篇:c#索引器
下一篇:c# 关键字
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站