1. 程式人生 > >asp.net的mvc開發標籤的使用

asp.net的mvc開發標籤的使用

  public class helloController : Controller
    {
        //
        // GET: /hello/
        [HttpGet]
        public ActionResult Index(int id,string name)
        {
            user u = new user();
            u.id = 1;
            u.name = "tom";
            u.sex = true;
            return View(u);
        }
        public class user
        {
           public int id{ set;get;}
           public string name{set;get;}
           public bool sex { get; set; }
        }

cshtml

@{
    Layout = null;
}

@model MvcApplication1.Controllers.helloController.user
<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    <div>
        @Html.EditorFor(name=>Model.name) <br />
        @Html.CheckBoxFor(sex=>Model.sex)
        @Html.BeginForm("","")
        {

        }

    </div>
</body>
</html>