When I create the view from controller, this error window keep popping up.
There was an error running the selected code generator.
'The value -1 is outside the acceptance range of [0,2147483647].
Parameter name: value'
Before this, I also refer from other post like Can't Add View from Controller in VS 2015 : "There was an error running the selected code generator" .But, this error window still there. How can I solve this error?
Below the code is the controller code. Before edit that, there is no any problem.
using Food_Founder.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace Food_Founder.Controllers
{
public class UserController : Controller
{
// GET: User
[HttpGet]
public ActionResult AddOrEdit(int UserID=0)
{
return View();
}
[HttpPost]
public ActionResult AddOrEdit(User Register)
{
using (myDatabaseEntities myDatabase = new myDatabaseEntities())
{
myDatabase.Users.Add(Register);
myDatabase.SaveChanges();
}
ModelState.Clear();
ViewBag.SuccessMessage = "Successful register account.";
return View("AddOrEdit", new User());
}
public ActionResult Login()
{
return View();
}
[HttpPost]
public ActionResult Login(User Login)
{
using (myDatabaseEntities myDatabase = new myDatabaseEntities())
{
var user = myDatabase.Users.Single(u => u.Username == Login.Username && u.Password == Login.Password);
if (user != null)
{
Session["UserID"] = user.UserID.ToString();
Session["Username"] = user.Username.ToString();
return RedirectToAction("LoggedIn");
}
else
{
ModelState.AddModelError("", "Username or Password is wrong");
}
}
return View();
}
public ActionResult LoggedIn()
{
if (Session["UserID"] != null)
{
return View();
}
else
{
return RedirectToAction("Login");
}
}
}
}