asp.net-mvc-5.1

Why am I getting an IdentityRole error?

时光毁灭记忆、已成空白 提交于 2019-11-30 16:03:31
Using Identity 2.0 After registering a user, the user is created in the database, there is code in the Account controller to create an identity and sign the user in. This is when I get the error. Here is the code producing the error: var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); And here is the error: The entity type IdentityRole is not part of the model for the current context. My Model looks like this: namespace MyApp.Models { public class ApplicationUser : IdentityUser { [Required] [StringLength(50)] public string FirstName { get;

How to set the selected value in EnumDropDownListFor?

故事扮演 提交于 2019-11-30 08:59:38
问题 I'm using MVC 5.2.0 and I'm trying to use the new Html.EnumDropDownListFor . This is how I'm setting the values: //Model public class MyModel { public int SelectedEnumId { get; set; } public TestEnum MyEnum { get; set; } } //Enum public enum TestEnum : int { name1 = 1, name2 = 2 } //View @Html.EnumDropDownListFor(model => model.MyEnum,new { @class = "form-control" }) This is working and the values are being displayed. But how do I set the selected value (SelectedEnumId)? Normally I would use

The type 'Expression<>' is defined in an assembly that is not referenced

半世苍凉 提交于 2019-11-30 02:33:00
In ASP.NET MVC 4.5.2 Framework. after typing @Html.LabelFor() or @Html.EditorFor() in view I'm getting Error: The type 'Expression<>' is defined in an assembly that is not referenced.You must add a reference to assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. I have added assembly reference System.Core.dll, Version 4.0.0.0, Runtime Version v4.0.30319. and also i did in web.config Prashant2008 I have run in the same issue as you, albeit much later. The issue was that I was not able to access Razor views (.cshtml) as I was getting an error stating that I

How to find the right route in a RouteCollectionRoute?

a 夏天 提交于 2019-11-30 02:30:03
问题 I am testing ASP MVC routes. I am having an issue with attribute routes in ASP MVC 5.1 When I have a controller like this: public class FooController : Controller { [Route("foo")] [HttpGet] public ActionResult Get() { .... } [Route("foo")] [HttpPost] public ActionResult Post() { .... } } Then in order to test which route matches a particular request, I call routes.GetRouteData. I get a System.Web.Routing.RouteData that contains the route as well as values that should say which controller and

Why am I getting an IdentityRole error?

随声附和 提交于 2019-11-29 23:45:24
问题 Using Identity 2.0 After registering a user, the user is created in the database, there is code in the Account controller to create an identity and sign the user in. This is when I get the error. Here is the code producing the error: var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); And here is the error: The entity type IdentityRole is not part of the model for the current context. My Model looks like this: namespace MyApp.Models {

When performing post via ajax, Bad Request is returned instead of the JSON result

末鹿安然 提交于 2019-11-29 23:03:34
Javascript jqXHR = $.ajax({ url: $frm.attr("action"), type: "POST", dataType: "json", cache: false, headers: headers, contentType: "application/json;charset=UTF-8", data: ko.mapping.toJSON(data, map), beforeSend: function(x) { if (x && x.overrideMimeType) { return x.overrideMimeType("application/json;charset=UTF-8"); } } }); jqXHR.fail(function(xhr, err, msg) { /* xhr.responseText NEED TO BE JSON!!! */ }); In Chrome Headers Request Method:POST Status Code:400 Bad Request Request Headersview source Accept:application/json, text/javascript, */*; q=0.01 Accept-Encoding:gzip,deflate,sdch Accept

No users have been created during Seed method using UserManager in ASP .NET MVC applications

最后都变了- 提交于 2019-11-29 11:37:51
When the Seed method runs, records/objects are added to my database. Every object is added as it should till I try add users to my application(at the bottom of Seed method). No one is added. Also there is lot of SQL exceptions thrown posted at the bottom. They are thrown even if Seed method is empty. How to add users to Entity Framework managed database? I created my code following Scott Allen's tutorial. protected override void Seed(WebApplication2.Models.ApplicationDbContext context) { System.Diagnostics.Debug.WriteLine("Seed started");//IT WORKS if (!context.Persons.Any()) { var persons =

Asp.net razor textbox array for list items

天大地大妈咪最大 提交于 2019-11-29 09:43:50
I can't find or figure out how to take a list of items (cupcakes) and display them in razor with a quantity field. What is happening is I am not able to get the values for each cupcake quantity in the list. Can you do textbox arrays in Razor? VIEW <div class="form-group"> <label>Cupcakes</label> @foreach (var cupcake in Model.CupcakeList) { @Html.TextBox("CupcakeQuantities", cupcake.Id) @cupcake.Name <br/> } </div> MODEL public List<Cupcake> CupcakeList { get; set; } public List<int> CupcakeQuantities { get; set; } CONTROLLER public ActionResult Create() { var model = new PartyBookingModel() {

Displaying DateTime picker instead of Date picker in ASP .NET MVC 5.1/HTML 5 specific

穿精又带淫゛_ 提交于 2019-11-29 03:09:14
I write application in ASP .NET MVC 5.1 I have a field: [DisplayName("Date of Birth")] [DataType(DataType.Date)] public DateTime BirthDate { get; set; } and then in View <div class="form-group"> @Html.LabelFor(model => model.BirthDate, htmlAttributes: new { @class = "control-label col-md-2" }) <div class="col-md-10"> @Html.EditorFor(model => model.BirthDate, new { htmlAttributes = new { @class = "form-control" } }) @Html.ValidationMessageFor(model => model.BirthDate, "", new { @class = "text-danger" }) </div> </div> which translates to: if I just change annotiations above property in model to:

The type 'Expression<>' is defined in an assembly that is not referenced

我的梦境 提交于 2019-11-28 23:30:17
问题 In ASP.NET MVC 4.5.2 Framework. after typing @Html.LabelFor() or @Html.EditorFor() in view I'm getting Error: The type 'Expression<>' is defined in an assembly that is not referenced.You must add a reference to assembly 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. I have added assembly reference System.Core.dll, Version 4.0.0.0, Runtime Version v4.0.30319. and also i did in web.config 回答1: I have run in the same issue as you, albeit much later. The issue