asp.net mvc - How can I log benchmark tests to CSV file in MVC controllers?

I have an ASP.NET Core app with various controllers that inherit from BaseController. I need to implement some basic benchmarking tests, using Stopwatch, it will just start at the beginning of an action method and finish at the end. I can turn this on and off via appsettings.json. There is an ILogger factory in Startup.cs:public void Configure ( IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory ) { loggerFactory.AddConsole( Configuration.GetSection( "Logging" ) ); loggerFactory.AddDebug(); l...Read more

asp.net mvc - bootstrap 4.0 navbar links not redirecting with razor

Hello I am working with bootstrap 4.0, I have this code for my navbar<div class="collapse navbar-collapse" id="navbarSupportedContent"> <ul class="navbar-nav mr-auto"> <li class="nav-item"> @Html.ActionLink("Manage assistants", "Index", "Assistant", new { @class = "nav-link" }) </li>....My problem is that when I try to redirect to assistantcontroller/index, the navbar link is redirecting to localhostxxx/?lenght=8What is going on here? Am I missing something?thanks...Read more

asp.net mvc - SignalR 2, Autofac 3.5, MVC 5 and OWIN: How to inject SignalR hub into a controller?

I'm trying to add a notification system to my MVC web app using SignalR. I want to trigger notifications when certain actions occur in the controllers.Getting the SignalR 2 up and running was a doddle thanks to Microsoft's excellent SignalR documentation, but I'm struggling to work out how to now change that code to use Autofac for DI, so that I can inject the hub, or something that allows me to access the hub, into controller.I've set up the Autofac dependency resolver as per the example in the Autofac documentation:public class Startup{ p...Read more

asp.net mvc - Error handling last chance to catch View Rendering exception

I've got ErrorController which customly handles my website errors.It's pretty standard:public class ErrorController : BaseController{ public ActionResult Error404(Exception ex) { return View(); } public ActionResult Error500(Exception ex) { return View(); }}However, in case if some rendering exception occurs inside of the View code (and this might occur, as the page has Master page (master layout) and different might happen), then I am not able to catch that rendering exception.I can really see that exception wit...Read more

asp.net mvc - Incorrect URL after changing routing in Area

I am having trouble with rendering URL addresses after changing routing.Routing Configurationpublic class AccountArea : AreaRegistration{ public override void RegisterArea(AreaRegistrationContext context) { context.MapRoute( "Account", "Account/{controller}/{action}/{id}", new { controller = "User", action = "Index", id = UrlParameter.Optional }, namespaces: new[] { "Application.Controllers.Account" } ); } public override string AreaName => "Acco...Read more

asp.net mvc - How to pass model values from a view to a controller?

I'm using VSCode in Mac creating a MVC.The parameter "new { problem = @Model }" shouldn't pass the values from the view to the controller?View code:@model ProblemsV4.Models.ProblemModel<h2>New Solution</h2>@using(Html.BeginForm("SaveSolution", "Problem", new { problem = @Model }, FormMethod.Get)){ <label>Solution: </label> <input type="text" name="solution" /><br/><br/> <input type="submit" value="Save"/>} Controller code:public IActionResult SaveSolution(ProblemModel problemModel, string...Read more

asp.net mvc - Zen barcode render with mvc

I am using Zen barcode framework with MVC, The barcode is rendering just fine but due to adding a new route for to support the barcode in the Route.configpublic static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); Allow extensionless handling of barcode image URIs routes.Add( "BarcodeImaging", new Route( "Barcode/{id}",new BarcodeImageRouteHandler())); routes.MapRoute( name: "Default", url: "{controller}/{a...Read more

asp.net mvc - Why should we add Model reference separately to MVC front end instead of using it from service reference?

In older web projects that I worked on, we used to create models in DAL, add reference of DAL in Business Logic Layer (and reuse models from DAL as they would be available with reference of DAL), Add reference of BL in Service (again reuse models). Entities were available transitively in all successive layers.In a MVC project with multiple layers, Models are often added in a separate class library project and referenced across all layers like DAL, Business Logic, Service, FrontEnd etc; Even though they are transitively available. Is there any s...Read more

active menu item - asp.net mvc3 master page

I've been scanning around trying to find an appropriate solution for assigning "active/current" class to menu items from the master page. The line is split down the middle with regards of whether to do this client vs server side.Truthfully I'm new to both JavaScript and MVC so i don't have an opinion. I would prefer to do this in the "cleanest" and most appropriate way.I have the following jQuery code to assign the "active" class to the <li> item...the only problem is the "index" or default view menu item will always be assigned the acti...Read more