<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>Learn MVC Project in 7 days – Day 2 – Lab 4 – Using ViewBag</title>
        <description>=======================================================


[url=https://www.codeproject.com/articles/897559/learn-mvc-in-days-day]Learn MVC Project in 7 days – Day 2[/url]


=======================================================

[url=https://www.codeproject.com/articles/897559/learn-mvc-in-days-day#Lab4%E2%80%93UsingViewBag]Lab 4 – Using ViewBag[/url]
Lab 4 – 使用「ViewBag」)

=======================================================

目的：
(一)了解 Action Method 與 View 之間 傳遞 資料 的其中一種方法


=======================================================


步驟：(詳見原文)


(一)建立一個  ViewBag

  接續 Lab3 的步驟，並把 Lab3 的  Step 3 的 View 內容 改成下面的程式

[code]
ViewBag.Employee = emp;
return View(&quot;MyView&quot;);
[/code]


(二)在 View 裡面 印出 Employee 的資料

    接續 Lab3 的步驟，並把 Lab3 的  Step 4 的 View 內容 改成下面的程式


[code]
@{
    WebApplication1.Models.Employee emp = (WebApplication1.Models.Employee)
        ViewBag.Employee;
}
Employee Details

Employee Name: @emp.FirstName @emp.LastName 

Employee Salary: @emp.Salary.ToString(&quot;C&quot;)
[/code]


(三)測試結果 

在網址列鍵入：localhost/Test/GetView

  結果如下：


[img]https://www.codeproject.com/KB/aspnet/897559/F.png[/img]


======================================================= 

討論： 

(一)</description>
        <link>http://mepopedia.com/forum/read.php?37,83879,83879#msg-83879</link>
        <lastBuildDate>Tue, 24 Nov 2026 14:08:54 +0800</lastBuildDate>
        <generator>Phorum 5.2.7</generator>
        <item>
            <guid>http://mepopedia.com/forum/read.php?37,83879,83879#msg-83879</guid>
            <title>Learn MVC Project in 7 days – Day 2 – Lab 4 – Using ViewBag</title>
            <link>http://mepopedia.com/forum/read.php?37,83879,83879#msg-83879</link>
            <description><![CDATA[=======================================================<br />
<br />
<br />
[url=https://www.codeproject.com/articles/897559/learn-mvc-in-days-day]Learn MVC Project in 7 days – Day 2[/url]<br />
<br />
<br />
=======================================================<br />
<br />
[url=https://www.codeproject.com/articles/897559/learn-mvc-in-days-day#Lab4%E2%80%93UsingViewBag]Lab 4 – Using ViewBag[/url]<br />
Lab 4 – 使用「ViewBag」)<br />
<br />
=======================================================<br />
<br />
目的：<br />
(一)了解 Action Method 與 View 之間 傳遞 資料 的其中一種方法<br />
<br />
<br />
=======================================================<br />
<br />
<br />
步驟：(詳見原文)<br />
<br />
<br />
(一)建立一個  ViewBag<br />
<br />
  接續 Lab3 的步驟，並把 Lab3 的  Step 3 的 View 內容 改成下面的程式<br />
<br />
[code]<br />
ViewBag.Employee = emp;<br />
<span style="font-size: 9pt;">return View("MyView");</span><br />
[/code]<br />
<br />
<br />
(二)在 View 裡面 印出 Employee 的資料<br />
<br />
    接續 Lab3 的步驟，並把 Lab3 的  Step 4 的 View 內容 改成下面的程式<br />
<br />
<br />
[code]<br />
@{<br />
    WebApplication1.Models.Employee emp = (WebApplication1.Models.Employee)<br />
        ViewBag.Employee;<br />
}<br />
Employee Details<br />
<br />
Employee Name: @emp.FirstName @emp.LastName <br />
<br />
Employee Salary: @emp.Salary.ToString("C")<br />
[/code]<br />
<br />
<br />
(三)測試結果 <br />
<br />
在網址列鍵入：localhost/Test/GetView<br />
<br />
  結果如下：<br />
<br />
<br />
[img]https://www.codeproject.com/KB/aspnet/897559/F.png[/img]<br />
<br />
<br />
======================================================= <br />
<br />
討論： <br />
<br />
(一)]]></description>
            <dc:creator>RandomVariable</dc:creator>
            <category>程式設計</category>
            <pubDate>Mon, 23 Jan 2017 04:40:25 +0800</pubDate>
        </item>
    </channel>
</rss>
