หากคุณต้องการแสดงซื่อ Controller หรือ Action ปัจจุบันที่กำลังเรียกใช้อยู่สามารถใช้คำส่งได้เลย ความจริงจะเรียกว่าคำสั่งก็คงไม่ถูกนัก ควรเรียกว่า object นี้หน้าจะถูกว่าเพราะมันอยู่ ใน HttpContext object ครับ คุณยังสามารถเรียกค่าของ id ได้ด้วยเพียงเปลี่ยนค่าในเครื่องหมายคำพูด ถ้าเรียกให้ถูกต้องก็คือ array key เป็น id ดังตัวอย่างด้านล่าง
@HttpContext.Current.Request.RequestContext.RouteData.Values["controller"]
@HttpContext.Current.Request.RequestContext.RouteData.Values["action"]
@HttpContext.Current.Request.RequestContext.RouteData.Values["id"]
Showing posts with label razor. Show all posts
Showing posts with label razor. Show all posts
April 15, 2014
March 28, 2014
เพิ่ม class attribute ใน @Html.EditorFor
หาคุณพยายามใส่ class attribute ใน Html.EditorFor แบบด้านล้าง คำตอบคือทำไม่ได้
@Html.EditorFor(x => x.Created, new {@class="one"})
ต้องเปลี่ยนเป็น Html.TextBoxForModel แทน
@Html.TextBoxForModel(x => x.Created, new { @class = "date" })
@Html.EditorFor(x => x.Created
ต้องเปลี่ยนเป็น Html.TextBoxForModel แทน
@Html.TextBoxForModel(x => x.Created, new { @class = "date" })
February 10, 2014
RenderPartial vs RenderAction vs Partial vs Action in MVC Razor
นี้เป็นวิธีการในการ render partal view ใน MVC Razor. หาย ๆ นักพัฒนาคิดความสับสนว่าใช้งานอย่างไร ระหว่าง RenderPartial หรือ RenderAction หรือ Partial หรือ Action helper methods จากการ render ตัว partial view. ในบทความนี้ จะอธิบายความแตกต่างระว่าง @Html.RenderPartial, @Html.RenderAction, @Html.Partial และ @Html.Action
@Html.RenderPartial
1. method นี้ ผลลัพท์จะเป็นการ directly written แบบ Http response stream หมายความว่ามันถูกใช้เหมือนกับ TextWriter object เช่นเดียวกับการใช้ในา webpage/template ปัจจุบัน
2. ตัว method จะ return void
3. ใช้งานง่ายโดยไม่ต้องสร้างตัว Action ใด ๆ ใน Controller
4. method @Html.RenderPartial มีประโยชน์ในการใช้เมื่อแสดง data ใน partial view in already in the corresponding view model.
@{ Html.RenderPartial("_Comments"); }
5. method นี้ เร็วกว่า method @Html.Partial โดย result ถูกส่งข้อความกับเป็น response stream ทำให้ทำงานได้เร็ว
September 23, 2011
ASP.NET MVC: Razor
ASP.NET MVC 3 Razor
Version: 1.1.0
รายละเอียด
ASP.NET MVC 3 ได้แนะนำ view engine ใหม่ชื่อ Razor, เป็นสิ่งทีมีความเข้าใจและทำให้ง่ายขึ้นจาก syntax ปัจจุบันที่ใช้อยู่คือ ASP.NET web page. ใน Lab นี้ คุณจะได้เรียนวิธีการสร้าง Razor view ภายใน MVC solution. ในการเริ่มต้นของ Lab คุณจะมีความคุ้นเคยกับ Razor syntax และความสามารถของมัน, ในแบบฝึกหัดที่ 2 คุณจะเพิ่ม Razor view ใน MVC Music Store solution ที่สร้างมาให้มีการทำงานเหมือนกับคุณทำงานกับ ASP.NET view, แต่เข้าใจง่ายกว่าและโค้ดที่สั้นกว่า. และที่ Lab สุดท้าย ในแบบฝึกหัดที่ 3, คุณจะเรียนรู้วิธีการสร้างและการเรียกใช้วาน Third party ของ Razor Helpers.
คำอธิบายแบบคร่าวๆ
บันทึก:
ใน Lab นี้ คิดว่าคุณมีความรู้พื้นฐานเดียวกับ ASP.NET MVC. ถ้าคุณไม่เคยใช้ ASP.NET MVC มาก่อน, เราแนะนำให้คุณไปดู ASP.NET MVC Fundamentals Hand-on Lab.
ASP.NET MVC 3 เพิ่ม view engine ใช่ชื่อ Razor, ซึ่งเป็นสิ่งที่ง่ายต่อการเข้าใจจาก syntax ที่ใช้อยู่ในปัจจุบันของ ASP.NET web pages. ใน Lab นี้, คุณจะได้เรียนรู้วิธีสร้าง Razor views ภายใน MVC solution.
Subscribe to:
Posts (Atom)