I am trying to make a simple web app. I have a User table which is just an id, name, password and email. The id is a counter so thats assigned automatically. I have a User/Create action which adds a user to the database. They fill out their name, password and email and click submit.
My problem is that the field isn't submitting and what is stranger is, it is the exact same code I have for an "Entry" controller and that works fine..
Code:
public interface IUserRepository {
IQueryable<User> FindAllUsers();
User GetUser(int id);
void Add(User user);
void Update(User user);
void Delete(User user);
}
...
public void Add(User user) {
db.Users.InsertOnSubmit(user);
db.SubmitChanges();
}
...
public ActionResult Create()
{
return View();
}
//
// POST: /User/Create
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(User user)
{
if(ModelState.IsValid){
try
{
_repository.Add(user);
return RedirectToAction("Index");
}
catch
{
return View(user);
}
}
else
{
return View(user);
}
}
Does anyone know what is wrong? Just to clarify, the when submit is pressed, it loads the form again. It doesn't redirect back to the index.