ASP.NET

Showing posts with label Visual studio. Show all posts
Showing posts with label Visual studio. Show all posts

Monday, July 10, 2017

การเพิ่ม Search Method และ Search View

จากหน้าจอ Index ที่ List รายชื่อ Movie หากต้องการทำส่วนค้นหาข้อมูล เช่น Title , Genre จะทำอย่างไร

ตัวอย่าง

จากไฟล์ Views/Movies/Index.cshtml เพิ่ม Code ด้านล่าง
 @model IEnumerable<MvcMovie.Models.Movie>  
 @{  
   ViewBag.Title = "Index";  
 }  
 <h2>Index</h2>  
 <p>  
   @Html.ActionLink("Create New", "Create")  
   @using (Html.BeginForm("Index", "Movies", FormMethod.Get))  
   {  
   <p>  
     Title: @Html.TextBox("SearchString")  
     Genre: @Html.DropDownList("movieGenre", "All")  
     <input type="submit" value="Filter" />  
   </p>  
   }  
 </p>  
 <table class="table">  

Focus การทำงานที่ Mode Edit

Post นี้จะมา Focus การทำงานที่ Mode Edit

ตัวอย่าง
หากต้องการแก้ไข Display Name สามารถกำหนดผ่านไฟล์ Models/Movie.cs

เช่น

 using System;  
 using System.ComponentModel.DataAnnotations;  
 using System.Data.Entity;  
 namespace MvcMovie.Models  
 {  
   public class Movie  
   {  
     public int ID { get; set; }  
     public string Title { get; set; }  
     [Display(Name = "Release Date")]  
      public string Genre { get; set; }  
     public decimal Price { get; set; }  
   }  
   public class MovieDBContext : DbContext  
   {  
     public DbSet<Movie> Movies { get; set; }  
   }  
 }  

การเพิ่ม Controller เพื่อจัดการข้อมูลใน SQL Server

ในส่วนนี้จะลองสร้าง MovieController เพื่อจัดการข้อมูล Model Movie

ตัวอย่าง

เริ่มจากการคลิกขวา Add > Controller


Sunday, July 9, 2017

การเพิ่ม Model ให้กับ Application

เริ่มจากการสร้าง Model ด้วยการสร้าง Class ภายใต้ Folder Models>Add>Class

การเพิ่ม View ให้กับ Application


การเรียกใช้งานส่วนของ View จะเริ่มจากการปรับแต่งส่วนของ Controller ให้เรียกการทำงาน View

ตัวอย่าง

HelloWorldController.cs ปรับแต่ง Method Index ให้เรียกใช้ View ดังรูป



เชื่อม SQL Server บน VMWare ผ่าน SQL Server Management Studio ที่เครื่อง Client

หากติดตั้ง SQL Server ต่างเครื่องคอมพิวเตอร์ที่เราต้องการ Develop จะต้อง Set ค่าเพิ่มเติมผ่าน SQL Server Configuration Server ด้วย เพราะไม...