Quantcast
Channel: MEPO Forum - 程式設計
Viewing all articles
Browse latest Browse all 99

Learn MVC Project in 7 days – Day 2 – Lab 4 – Using ViewBag (no replies)

$
0
0
=======================================================


Learn MVC Project in 7 days – Day 2


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

Lab 4 – Using ViewBag
Lab 4 – 使用「ViewBag」)

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

目的:
(一)了解 Action Method 與 View 之間 傳遞 資料 的其中一種方法


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


步驟:(詳見原文)


(一)建立一個 ViewBag

接續 Lab3 的步驟,並把 Lab3 的 Step 3 的 View 內容 改成下面的程式

ViewBag.Employee = emp;
return View("MyView");


(二)在 View 裡面 印出 Employee 的資料

接續 Lab3 的步驟,並把 Lab3 的 Step 4 的 View 內容 改成下面的程式


@{
    WebApplication1.Models.Employee emp = (WebApplication1.Models.Employee)
        ViewBag.Employee;
}
Employee Details

Employee Name: @emp.FirstName @emp.LastName 

Employee Salary: @emp.Salary.ToString("C")


(三)測試結果

在網址列鍵入:localhost/Test/GetView

結果如下:


https://www.codeproject.com/KB/aspnet/897559/F.png


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

討論:

(一)

Viewing all articles
Browse latest Browse all 99

Trending Articles