Week5(10月10日):国庆之后,让我们整装期待元旦吧

本文介绍如何在ASP.NET MVC应用中通过ViewData和ViewBag将数据从控制器传递到视图,并展示了如何利用强类型传递实现学生信息列表的展示。此外,还提供了留言功能实现的具体要求。

Part I:提问 

===========================

 1.要将“Hello, Admin",从控制器传递到视图,该如何操作?

(1)使用ViewData

(2)使用ViewBag

2.已知某学生类Student.cs,控制器中Index动作将学生传递给视图,请解释强类型传递的原理。

public ActionResult Index()
        {
            return View(db.Students.ToList());
        }
@model IEnumerable<tempPractice.Models.Student>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table>
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.StuNo)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Phone)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.StuNo)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Phone)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id=item.Id }) |
            @Html.ActionLink("Details", "Details", new { id=item.Id }) |
            @Html.ActionLink("Delete", "Delete", new { id=item.Id })
        </td>
    </tr>
}

</table>

 

Part II:Ch03 视图3

===========================

要点:

    1.知识点3-5:使用强类型模板

    2.知识点3-6:HTML辅助方法

    3.动手吧>>:在自己的大作业网站中,实现留言功能。要求如http://192.168.55.163/TakeLearning所示。

 

转载于:https://www.cnblogs.com/meetyy/p/4009389.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值