Hi,
I am trying to learn ( at my advanced age) the MVC method of developing .NET web apps, but, in trying the tutorials here using virtual Web Developer 2008 Express :
I cannot seem to get the databse to update with new records.
I am using the Movie Database video tutorial i c# and get no error messages but , except for the List ( index) page which shows the records in my database, the other views/actions do not have any effect.
I have this HomeController
And This is the Create view page:
The database is the included SqlServer 2008 Express
and I can, using the Data Explorer, add records directly, just not from these pages.
What am I missing, or what additional info do you need to assist.
Thanks
To Paraphrase:"The Help you get is proportional to the Help you give.."
I am trying to learn ( at my advanced age) the MVC method of developing .NET web apps, but, in trying the tutorials here using virtual Web Developer 2008 Express :
I cannot seem to get the databse to update with new records.
I am using the Movie Database video tutorial i c# and get no error messages but , except for the List ( index) page which shows the records in my database, the other views/actions do not have any effect.
I have this HomeController
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using MovieApp.Models;
namespace MovieApp.Controllers
{
public class HomeController : Controller
{
private MoviesDBEntities _entities = new MoviesDBEntities();
//
// GET: /Home/
public ActionResult Index()
{
return View(_entities.MovieSet.ToList());
}
//
// GET: /Home/Details/5
public ActionResult Details(int id)
{
return View();
}
//
// GET: /Home/Create
public ActionResult Create()
{
return View();
}
//
// POST: /Home/Create
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create([Bind(Exclude="Id")]Movie movieToCreate)
{
try
{
// TODO: Add insert logic here
_entities.AddToMovieSet(movieToCreate);
_entities.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
//
// GET: /Home/Edit/5
public ActionResult Edit(int id)
{
return View();
}
//
// POST: /Home/Edit/5
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(int id, FormCollection collection)
{
try
{
// TODO: Add update logic here
return RedirectToAction("Index");
}
catch
{
return View();
}
}
}
}
And This is the Create view page:
Code:
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MovieApp.Models.Movie>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Create
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>Create</h2>
<%= Html.ValidationSummary("Create was unsuccessful. Please correct the errors and try again.") %>
<% using (Html.BeginForm()) {%>
<fieldset>
<legend>Fields</legend>
<p>
<label for="Title">Title:</label>
<%= Html.TextBox("Title") %>
<%= Html.ValidationMessage("Title", "*") %>
</p>
<p>
<label for="Director">Director:</label>
<%= Html.TextBox("Director") %>
<%= Html.ValidationMessage("Director", "*") %>
</p>
<p>
<label for="DateReleased">DateReleased:</label>
<%= Html.TextBox("DateReleased") %>
<%= Html.ValidationMessage("DateReleased", "*") %>
</p>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
<% } %>
<div>
<%=Html.ActionLink("Back to List", "Index") %>
</div>
</asp:Content>
The database is the included SqlServer 2008 Express
and I can, using the Data Explorer, add records directly, just not from these pages.
What am I missing, or what additional info do you need to assist.
Thanks
To Paraphrase:"The Help you get is proportional to the Help you give.."