asp.net-mvc-5

MVC Route Map Got Exception on Html.RenderAction : No route in the route table matches the supplied values

拜拜、爱过 提交于 2019-12-31 03:59:14
问题 I use ASP.NET MVC 5 and this is My Route Map for all of the actions except Home/index : routes.MapRoute( name: "randomNumber", url: "{controller}/{randomNumber}/{action}", defaults: new { }, constraints: new { randomNumber = @"\d+" } ); And for first page: Home/Index I don't want to use {randomNumber} So the first solution I think is: routes.MapRoute( name: "Default", url: "{controller}/{action}", defaults: new { controller = "Home", action = "Index" } ); This route map solve my problem, but

Customized DataAnnotationsModelMetadataProvider not working

♀尐吖头ヾ 提交于 2019-12-31 03:27:06
问题 I have many properties that require 1 or more validation attributes, like the following: public class TestModel { [Some] [StringLength(6)] [CustomRequired] // more attributes... public string Truck { get; set; } } Please note all the above annotations work. I do not want to write that all the time because whenever Some is applied, all other attributes are also applied to the property. I want to be able to do this: public class TestModel { [Some] public string Truck { get; set; } } Now this is

Recommended way to handle http errors inside my asp.net mvc 5 web application

倾然丶 夕夏残阳落幕 提交于 2019-12-31 03:04:19
问题 i need a way to globally handle http errors inside my asp.net mvc web application. i did the following if the call to the action method is Ajax :- $(document).ready(function () { $(document).ajaxError(function (e, xhr, textStatus, errorThrown) { if (xhr.status == 401) window.location = "/Account/Login"; else if (xhr.status == 403 || xhr.status == 404) alert(xhr.statusText, 'Error'); $(".loadingimage").hide(); }); where my action method looks as follow:- [CheckUserPermissions(Action = "Edit",

Recommended way to handle http errors inside my asp.net mvc 5 web application

别说谁变了你拦得住时间么 提交于 2019-12-31 03:03:05
问题 i need a way to globally handle http errors inside my asp.net mvc web application. i did the following if the call to the action method is Ajax :- $(document).ready(function () { $(document).ajaxError(function (e, xhr, textStatus, errorThrown) { if (xhr.status == 401) window.location = "/Account/Login"; else if (xhr.status == 403 || xhr.status == 404) alert(xhr.statusText, 'Error'); $(".loadingimage").hide(); }); where my action method looks as follow:- [CheckUserPermissions(Action = "Edit",

BundleTable.EnableOptimizations true breaks jquery-ui all.css

元气小坏坏 提交于 2019-12-30 23:51:30
问题 In an Asp.Net MVC 5 application, I am creating a style bundle in my egisterBundles method. I'm using jquery-ui . Instead of listing all of the jquery-ui css files individually I'm using all.css , which imports all the rest. The code looks like this: bundles.Add(new StyleBundle("~/Content/css").Include( "~/Content/a.css", "~/Content/b.css", "~/Content/themes/base/all.css")); And all.css contains two lines: @import "base.css"; @import "theme.css"; This works, but only when I set BundleTable

Is there a way to create a custom User and Role without specifying the TKey on IdenitityUser, IdentityRole, and IdentityDbContext?

北城以北 提交于 2019-12-30 11:21:19
问题 Is there a way to create a custom User and Role without specifying the TKey string in IdentityUser , IdentityRole , and IdentityDbContext ? I ask because it seems to think I don't want the auto-generated primary key Id anymore and I absolutely do. Doing what I've done below, UserManager.Create(user, password) will fail with an EntityValidationError on Id . public class ApplicationUser : IdentityUser<string, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim> { [Required]

Get ASP.NET MVC5 WebAPI token fails sometimes

孤街浪徒 提交于 2019-12-30 11:03:27
问题 Get ASP.NET MVC5 WebAPI token fails sometimes Code string GetAPITokenSync(string username, string password, string apiBaseUri) { var token = string.Empty; using (var client = new HttpClient()) { client.BaseAddress = new Uri(apiBaseUri); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.Timeout = TimeSpan.FromSeconds(60); //setup login data var formContent = new FormUrlEncodedContent(new[] { new

Get ASP.NET MVC5 WebAPI token fails sometimes

十年热恋 提交于 2019-12-30 11:03:19
问题 Get ASP.NET MVC5 WebAPI token fails sometimes Code string GetAPITokenSync(string username, string password, string apiBaseUri) { var token = string.Empty; using (var client = new HttpClient()) { client.BaseAddress = new Uri(apiBaseUri); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.Timeout = TimeSpan.FromSeconds(60); //setup login data var formContent = new FormUrlEncodedContent(new[] { new

“No IUserTokenProvider is registered” when using structuremap dependency injection

拈花ヽ惹草 提交于 2019-12-30 09:47:29
问题 I have an MVC 5 project that has been modified to use int as the primary key for identity as shown in this guide I then enabled email confirmation as described in this guide Everything worked fine as expected. Then I installed structuremap.mvc5 for dependency injection and added modified DefaultRegistry.cs to public DefaultRegistry() { Scan( scan => { scan.TheCallingAssembly(); scan.WithDefaultConventions(); scan.AssemblyContainingType(typeof(MyProject.Data.MyDbContext)); scan.With(new

How to pass Array to MVC Controller with Jquery?

拈花ヽ惹草 提交于 2019-12-30 07:51:53
问题 I am beginner to develope .Net MVC 5 application. But I have some problem with passing array or object to controller with Jquery. I'm adding dynamically input fields with button. I want to pass input's data to controller. But I couldn't succeed. Html Section is like that; <div id='TextBoxesGroup'> <div id="TextBoxDiv1"> <label>Textbox #1 : </label><input type='text' id='textbox1'> </div> </div> <input type='button' value='Add Button' id='addButton'> <input type='button' value='Remove Button'