我是ASP.NET MVC的新手。我需要創建一個動作結果來顯示我的列表的內容。如何添加動作結果? mvc5
我在Movie.cs類下面的代碼。我需要幫助創建操作結果。我的代碼是:
namespace MvcMovie.Models
{
public class Movie
{
public int ID { get; set; }
public string Title { get; set; }
public DateTime ReleaseDate { get; set; }
public string Genre { get; set; }
public decimal Price { get; set; }
}
public class MovieDBContext : DbContext
{
public List<Movie> GetMoviesList()
{
List<Movie> lmovie = new List<Movie>();
SqlConnection con = new SqlConnection("Data Source=dev01;Initial Catalog=Test;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("select * from Movies", con);
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
con.Close();
foreach (DataRow r in dt.Rows)
{
Movie mv = new Movie();
mv.ID = Convert.ToInt32(r["ID"]);
mv.Title = r["Title"].ToString();
mv.Price = Convert.ToInt32(r["Price"]);
mv.ReleaseDate = Convert.ToDateTime(r["ReleaseDate"]);
mv.Genre = r["Genre"].ToString();
lmovie.Add(mv);
}
return lmovie;
}
}
}
這是我行動的結果在MoviesController:
public ActionResult Index()
{
return View(-----);
}
試試閱讀以瞭解Asp.Net MVC的基礎 - > http://www.asp.net/mvc/tutorials/mvc-5/introduction/getting-started並讓我知道 –