asp.net mvc筆記


1.方法到視圖數據傳遞.
   使用ViewData["ParaName"]或ViewBag.ParaName.
2.視圖的頭
   <head>
    <meta name="viewport" content="width=device-width" />
    <title>Index-MyApp</title>
    <link href="~/Content/Style.css" rel="stylesheet" />
    <link href="~/Content/bootstrap.css" rel="stylesheet" />
    <link href="~/Content/bootstrap.min.css" rel="stylesheet" />
   </head>
3.視圖的轉頁
   @Html.ActionLink("linkText", "actionName", "controllerName", routeValues, htmlAttributes)
   如:
,@Html.ActionLink("詳情", "Detail", "Student","new{ id = 1 }, new{ target = "_blank" }代表
<a href="Student/Detail/1" target="_blank">詳情</a>
4.強類型視圖
   @model SpaceName.Models.ModelClassName

@using (Html.BeginForm())
    {
        @Html.ValidationSummary()
        <div class="form-group">
            <label>Your Name :</label>
            @Html.TextBoxFor(x => x.Name, new { @class = "formcontrol" })
        </div>
       <div class="form-group">
           <label>Your Email :</label>
           @Html.TextBoxFor(x => x.Email, new { @class = "formcontrol" })
       </div>
       <div class="form-group">
            <label>can you join us?</label>
            @Html.DropDownListFor(x => x.WillAttend, new[]{ new SelectListItem(){ Text="Yes,I do.",Value=bool.TrueString},new SelectListItem(){ Text = "No,I don't", Value = bool.FalseString } },"請選擇",new {@class="formcontrol"})
        </div>
        <div class="text-center"><input class="btn btn-success" type="submit" value="Submit"></div>
    }    
5.控制器的get和post方法

      // 展示輸入界面
       [HttpGet]
        public ViewResult InputInfo()
        {
            return View();
        }

        //在輸入界面中按提交按鈕後的處理

       //Result 視圖是一個強視圖
        [HttpPost]
        public ViewResult InputInfo(ModelClassName modelObject)
        {
            return View("Result",modelObject);
        }


 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章