Welcome! 登入 註冊
美寶首頁 美寶百科 美寶論壇 美寶落格 美寶地圖

Advanced

Change History

Message: Learn MVC Project in 7 days – Day 2 – Lab 5 - Understand strongly typed Views

Changed By: RandomVariable
Change Date: January 31, 2017 02:28AM

Learn MVC Project in 7 days – Day 2 – Lab 5 - Understand strongly typed Views
Changed By: RandomVariable
Change Date: January 31, 2017 02:25AM

Learn MVC Project in 7 days – Day 2 – Lab 5 - Understand strongly typed Views
=======================================================


[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#Lab5-Understand strongly typed Views]Lab 5 - Understand strongly typed Views[/url]
Lab 3 – 了解 強型別 View

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

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


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


步驟:(詳見原文)

(一) 將 View 設定成 強型別( strongly typed )

在 View 的最上面 加上下列敘述

[code]
@model WebApplication1.Models.Employee
[/code]


這個使得 View 成為一個 型別 Employee 的 強型別 View ( strongly typed view )


(二)在 View 裡面 使用 變數資料






[code]
Employee Details

Employee Name : @Model.FirstName @Model.LastName

@if(Model.Salary>15000)
{
<span style="background-color:yellow">
Employee Salary: @Model.Salary.ToString("C")
</span>
}
else
{
<span style="background-color:green">

Employee Salary: @Model.Salary.ToString("C")
</span>
}
[/code]

(三) 將 Model 的資料從 Action Method 傳到 View

鍵入下列程式碼:

[code]
Employee emp = new Employee();
emp.FirstName = "Sukesh";
emp.LastName="Marla";
emp.Salary = 20000;
return View("MyView",emp);
[/code]

(四)測試結果:

[img]https://www.codeproject.com/KB/aspnet/897559/H.png[/img]
.Salary.ToString("C")
</span>
}
else
{
<span style="background-color:green">

Employee Salary: @Model.Salary.ToString("C")
</span>
}
[/code]

(三) 將 Model 的資料從 Action Method 傳到 View

鍵入下列程式碼:

[code]
Employee emp = new Employee();
emp.FirstName = "Sukesh";
emp.LastName="Marla";
emp.Salary = 20000;
return View("MyView",emp);
[/code]

(四)測試結果:

[img]https://www.codeproject.com/KB/aspnet/897559/H.png[/img]

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

討論:

(一)
Changed By: RandomVariable
Change Date: January 23, 2017 06:40PM

Learn MVC Project in 7 days – Day 2 – Lab 5 - Understand strongly typed Views
=======================================================


[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#Lab5-Understand strongly typed Views]Lab 5 - Understand strongly typed Views[/url]
Lab 3 – 了解 強型別 View

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

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


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


步驟:(詳見原文)

(一) 將 View 設定成 強型別( strongly typed )

在 View 的最上面 加上下列敘述

[code]
@model WebApplication1.Models.Employee
[/code]


這個使得 View 成為一個 型別 Employee 的 強型別 View ( strongly typed view )






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

討論:

(一)
(二)在 View 裡面 使用 變數資料





.Salary.ToString("C")
</span>
}
else
{
<span style="background-color:green">

Employee Salary: @Model.Salary.ToString("C")
</span>
}
[/code]

(三) 將 Model 的資料從 Action Method 傳到 View

鍵入下列程式碼:

[code]
Employee emp = new Employee();
emp.FirstName = "Sukesh";
emp.LastName="Marla";
emp.Salary = 20000;
return View("MyView",emp);
[/code]

(四)測試結果:

[img]https://www.codeproject.com/KB/aspnet/897559/H.png[/img]

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

討論:

(一)
Changed By: RandomVariable
Change Date: January 23, 2017 06:04PM

Learn MVC Project in 7 days – Day 2 – Lab 5 - Understand strongly typed Views
=======================================================


[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#Lab5-Understand strongly typed Views]Lab 5 - Understand strongly typed Views[/url]
Lab 3 – 了解 強型別 View

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

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


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


步驟:(詳見原文)

(一) 將 View 設定成 強型別( strongly typed )

在 View 的最上面 加上下列敘述

[code]
https://www.codeproject.com/articles/897559/learn-mvc-in-days-day#Lab5-UnderstandstronglytypedViews
[/code]


這個使得 View 成為一個 型別 Employee 的 強型別 View ( strongly typed view )
ew )
l WebApplication1.Models.Employee
[/code]


這個使得 View 成為一個 型別 Employee 的 強型別 View ( strongly typed view )






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

討論:

(一)(二)在 View 裡面 使用 變數資料





.Salary.ToString("C")
</span>
}
else
{
<span style="background-color:green">

Employee Salary: @Model.Salary.ToString("C")
</span>
}
[/code]

(三) 將 Model 的資料從 Action Method 傳到 View

鍵入下列程式碼:

[code]
Employee emp = new Employee();
emp.FirstName = "Sukesh";
emp.LastName="Marla";
emp.Salary = 20000;
return View("MyView",emp);
[/code]

(四)測試結果:

[img]https://www.codeproject.com/KB/aspnet/897559/H.png[/img]

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

討論:

(一)

Original Message

作者: RandomVariable
Date: January 23, 2017 05:10AM

Learn MVC Project in 7 days – Day 2 – Lab 5 - Understand strongly typed Views
=======================================================


[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#Lab5-Understand strongly typed Views]Lab 5 - Understand strongly typed Views[/url]
Lab 3 – 了解 強型別 View

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

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


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


步驟:(詳見原文)

(一) 將 View 設定成 強型別( strongly typed )

在 View 的最上面 加上下列敘述

[code]
https://www.codeproject.com/articles/897559/learn-mvc-in-days-day#Lab5-UnderstandstronglytypedViews
[/code]


這個使得 View 成為一個 型別 Employee 的 強型別 View ( strongly typed view )
l WebApplication1.Models.Employee
[/code]


這個使得 View 成為一個 型別 Employee 的 強型別 View ( strongly typed view )






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

討論:

(一)(二)在 View 裡面 使用 變數資料





.Salary.ToString("C")

}
else
{


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

}
[/code]

(三) 將 Model 的資料從 Action Method 傳到 View

鍵入下列程式碼:

[code]
Employee emp = new Employee();
emp.FirstName = "Sukesh";
emp.LastName="Marla";
emp.Salary = 20000;
return View("MyView",emp);
[/code]

(四)測試結果:

[img]https://www.codeproject.com/KB/aspnet/897559/H.png[/img]

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

討論:

(一)