asp.net-mvc-5

MVC Routing with no (or a default) action name

。_饼干妹妹 提交于 2020-01-25 09:52:10
问题 Using MVC 5, I am trying to get some friendly controller/action names working through routing. Banging my head against the wall with this. Given this controller: MyController Index(startPage, pageSize) EditAction(itemId) I am using two routes (defined under an inherited AreaRegistration class) context.MapRoute( "MyControllerRoute", "myArea/MyController/{action}/{itemId}", new { controller = "MyController", action = "Index", itemId = UrlParameter.Optional }, new[] {"MySite.Areas.MyArea

swagger error “Uncaught RangeError: Invalid string length” in mvc angularjs mix project

浪尽此生 提交于 2020-01-24 22:42:06
问题 I have a project in mvc5 and anguarjs mix and here I am trying to add swagger I had installed the latest Swashbuckle and tried this API which is working http://localhost:6790/swagger/docs/v1 and I could say that my json is valid and checked on https://editor.swagger.io but when I tied this on http://localhost:6790/swagger/ui/index (view) this shows error Uncaught RangeError: Invalid string length at JSON.stringify (<anonymous>) at t.exports.u.getModelSampleJSON (swagger-ui-min-js:formatted

Performance considerations with nested declarative @helpers in Razor

余生长醉 提交于 2020-01-24 10:06:29
问题 @helpers, along with partial views allow for great composability, however I would like to know if there is a significant performance cost to be aware. For example: App_Code\Wrappers.cshtml: @helper HeaderWrapper(WebViewPage view, Func<object, HelperResult> content,Func<object, HelperResult> navbar = null) { <div class="container-fluid"> @content(null) </div> if (navbar != null) { <div class="container-fluid"> <nav id="navbar-page" class="navbar-default navbar-collapse collapse" role=

How do I set the WWW-Authentication header in an IAuthenticationFilter implementation?

社会主义新天地 提交于 2020-01-24 04:11:25
问题 I'm implementing basic authentication using MVC5's IAuthenticationFilter interface. My understanding is that this is now the preferred approach instead of using a DelegatingHandler. I've got it working but the www-authenticate header is not being returned in the response. This is my implementation of ChallengeAsync: public async Task ChallengeAsync(HttpAuthenticationChallengeContext context, CancellationToken cancellationToken) { var result = await context.Result.ExecuteAsync

Pass selected DropDown value to the controller

大兔子大兔子 提交于 2020-01-23 12:30:30
问题 I have a DropDownList and a button on my View. On click of a button, I want to pass the selected DropDown value to the controller. How to do this? View code is as below: @model Sample2.Models.LeaveType @{ ViewBag.Title = "Status of Application"; } @{ List<SelectListItem> listItems = new List<SelectListItem>(); listItems.Add(new SelectListItem { Text = "All", Value = "A", Selected = true }); listItems.Add(new SelectListItem { Text = "Recommended", Value = "R" }); listItems.Add(new

Request Client Certificate

女生的网名这么多〃 提交于 2020-01-23 12:09:35
问题 I've seen a lot of unsolved questions about this. Apparently many developers have gotten past this issue, but I haven't seen any solutions posted. I'm trying to read a smart card (X.509 CAC) for my ASP.NET MVC 5 web app. When I try to pull the certificate information like this: var request = HttpContext.Request; var cert = request.ClientCertificate; The cert has empty values. The problem appears to be I am not presenting the dialog to request user certificate info like I see on other websites

How to render ModelMetadata object using Html.Displar in Razor-engine in ASP.NET MVC app?

南笙酒味 提交于 2020-01-23 10:50:47
问题 I am trying to utilize the DisplayTemplates feature in razor-engine to automate rendering my display views. I scan my Model to find the correct ModelMetadata for each property that I want to display. But I am not able to render the properties using Html.DisplayFor correctly. I tried to display my property like so // First I find the ModelMetadata for the property // I call this statement in a loop and each iteration I pass a different PropertyName to get the correct model ModelMetadata

AngularJs and ASP.NET MVC 5 - ng-model overriding textbox value

自作多情 提交于 2020-01-23 06:57:47
问题 I have a form built using ASP.NET MVC 5 using @Html.TextBoxFor to populate the form with my model (e.g, after a form navigation or server side validation failure). I have now introduced a client side address lookup using Angular which means some of the form fields are now decorated with ng-model to enable the Angular lookup to populate the searched address. e.g.: @Html.TextBoxFor(m => m.Town, new { @class="form-control", ng_model="address.town" }) Adding the ng-model now overrides the value

AngularJs and ASP.NET MVC 5 - ng-model overriding textbox value

不羁岁月 提交于 2020-01-23 06:57:07
问题 I have a form built using ASP.NET MVC 5 using @Html.TextBoxFor to populate the form with my model (e.g, after a form navigation or server side validation failure). I have now introduced a client side address lookup using Angular which means some of the form fields are now decorated with ng-model to enable the Angular lookup to populate the searched address. e.g.: @Html.TextBoxFor(m => m.Town, new { @class="form-control", ng_model="address.town" }) Adding the ng-model now overrides the value

How to implement a Unit of work containing the new IdentityUser

不羁的心 提交于 2020-01-22 22:38:09
问题 I am wondering what is the best way to add the UserManager to my Unit of work. Should I use the IUstrore interface and add a new UserManager in my controller? Should I just use UserManager in my UnitOfWork or should I do something different? Here is two ideas I had for my unit of work and controller implementation. public class UnitOfWorkPds : IUnitOfWorkPds, IDisposable { private ApplicationDbContext context = new ApplicationDbContext(); private IUserStore<ApplicationUser> userStore; public