Adding ASP.NET MVC5 Identity Authentication to an existing project

I have seen lots of similar pages on the web, but most of them use a new project instead of an existing one, or don’t have the necessary features. So, I have an existing MVC 5 project and want to integrate ASP.NET MVC5 Identity with log in, email confirmation and password reset features. In addition … Read more

The conversion of a datetime2 data type to a datetime data type resulted in an out-of-range value

I have the following code in my HomeController: public ActionResult Edit(int id) { var ArticleToEdit = (from m in _db.ArticleSet where m.storyId == id select m).First(); return View(ArticleToEdit); } [ValidateInput(false)] [AcceptVerbs(HttpVerbs.Post)] public ActionResult Edit(Article ArticleToEdit) { var originalArticle = (from m in _db.ArticleSet where m.storyId == ArticleToEdit.storyId select m).First(); if (!ModelState.IsValid) return View(originalArticle); _db.ApplyPropertyChanges(originalArticle.EntityKey.EntitySetName, ArticleToEdit); … Read more

How can I add a class attribute to an HTML element generated by MVC’s HTML Helpers?

ASP.NET MVC can generate HTML elements using HTML Helpers, for example @Html.ActionLink(), @Html.BeginForm() and so on. I know I can specify form attributes by creating an anonymous object and pass that object for the (fourth in this case) htmlAttributes parameter where specifying an id for the element: Html.BeginForm(“Foo”, “Bar”, FormMethod.Post, new { id = “MyForm”}) … Read more

Test method is inconclusive: Test wasn’t run. Error?

I have a test class and below I have posted a sample test from the test class namespace AdminPortal.Tests.Controller_Test.Customer { [TestClass] public class BusinessUnitControllerTests { private IBusinessUnitRepository _mockBusinessUnitRepository; private BusinessUnitController _controller; [TestInitialize] public void TestInitialize() { _mockBusinessUnitRepository = MockRepository.GenerateMock<IBusinessUnitRepository>(); _controller = new BusinessUnitController(_mockBusinessUnitRepository); } [TestCleanup] public void TestCleanup() { _mockBusinessUnitRepository = null; _controller.Dispose(); _controller = … Read more

include antiforgerytoken in ajax post ASP.NET MVC

I am having trouble with the AntiForgeryToken with ajax. I’m using ASP.NET MVC 3. I tried the solution in jQuery Ajax calls and the Html.AntiForgeryToken(). Using that solution, the token is now being passed: var data = { … } // with token, key is ‘__RequestVerificationToken’ $.ajax({ type: “POST”, data: data, datatype: “json”, traditional: true, … Read more

How to add/update child entities when updating a parent entity in EF

The two entities are one-to-many relationship (built by code first fluent api). public class Parent { public Parent() { this.Children = new List<Child>(); } public int Id { get; set; } public virtual ICollection<Child> Children { get; set; } } public class Child { public int Id { get; set; } public int ParentId { … Read more