Hello,
I am Creating MVC Application MvcMovies by guiding Asp.net tutorial(http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/accessing-your-model's-data-from-a-controller[^])
I have created sql server database and created a table Movies,
my only question is that where to store data after called savechanges()
if you want code than,
Below is my code model controller and view,
Movies.cs
public class Movies
{
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 string Ratings { get; set; }
}
public class MoviesDBContext : DbContext
{
public DbSet<Movies> Movies { get; set; }
}
MoviesController.cs
public ActionResult Create()
{
return View();
}
[HttpPost]
public ActionResult Create(Movies movies)
{
if (ModelState.IsValid)
{
db.Movies.Add(movies);
db.SaveChanges();
return RedirectToAction("Index");
}
return View(movies);
}
create.cshtml
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>Movies</legend>
<div class="editor-label">
@Html.LabelFor(model => model.title)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.title)
@Html.ValidationMessageFor(model => model.title)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.ReleaseDate)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.ReleaseDate)
@Html.ValidationMessageFor(model => model.ReleaseDate)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Genre)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Genre)
@Html.ValidationMessageFor(model => model.Genre)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.price)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.price)
@Html.ValidationMessageFor(model => model.price)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Ratings)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Ratings)
@Html.ValidationMessageFor(model => model.Ratings)
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
}
I need to know that when I am creating new record where it will be inserted.
I have checked database table but there is no records.
Thanks.