Hi I have Faced With a Problem When Im Trying To Register. This Is My Code :
public ActionResult RegisterButton(Models.Users User)
{
using (MyDbContext db = new MyDbContext())
{
if (ModelState.IsValid == false)
{
return View("Register", User);
}
else
{
db.Users.Add(User);
db.SaveChanges();
Session["UserId"] = User.Id;
//Directory.CreateDirectory(string.Format("~/App_Data/{0}",User.UserName+User.Id.ToString()));
return RedirectToAction("Profile", "Profile",new { User.Id});
}
}
}
And This Is Also My Route Config Code :
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
And I Get This Error : The parameters dictionary contains a null entry for parameter 'UserId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Profile(Int32)' in 'DigiDaroo.Controllers.ProfileController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Please Help:|