Why is ListBoxFor not selecting items, but ListBox is?

I’ve stumbled across this problem myself, finally I realized that the problem was a naming convention. You cannot name the ViewBag or ViewData poperty containing the SelectList or MultiSelectList to the same name your property model containing the selected items. At least not if you’re using the ListBoxFor or DropDownListFor helper. Here’s an example: public … Read more

Accessing UserManager outside AccountController

If you’re using the default project template, the UserManager gets created the following way: In the Startup.Auth.cs file, there’s a line like this: app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create); that makes OWIN pipeline instantiate an instance of ApplicationUserManager each time a request arrives at the server. You can get that instance from OWIN pipeline using the following code inside a … Read more

Error “More than one matching bindings are available” when using Ninject.Web.Mvc 2.0 and ASP.NET MVC 1.0

I finally figured this issue out recently. Apparently, the NinjectHttpApplication.RegisterAllControllersIn() function doesn’t do all of the proper bindings needed. It binds your concrete controller implementations to IController requests. For example, if you have a controller class called SampleMvcController, which inherits from System.Web.Mvc.Controller. It would do the following named binding during application start: kernel.Bind<IController>().To(SampleMvcController).InTransientScope().Named(“SampleMvc”); But when … Read more

ASP.NET MVC – Combine Json result with ViewResult

You can also render a PartialViewResult to a string, and then pass this string via JSON to your view, rendering it in your page using jQuery. You can see that in this post: http://www.atlanticbt.com/blog/asp-net-mvc-using-ajax-json-and-partialviews/. I’ve created an extension to make it easier: public static class MvcHelpers { public static string RenderPartialView(this Controller controller, string viewName, … Read more

How do I unit test a custom ActionFilter in ASP.Net MVC

You just need to test the filter itself. Just create an instance and call the OnActionExecuted() method with test data then check the result. It helps to pull the code apart as much as possible. Most of the heavy lifting is done inside the CsvResult class which can be tested individually. You don’t need to … Read more

Asp.Net MVC Themes, how to?

Here’s my code that I’ve been using for implementing “Themes” in ASP.NET MVC: ASP.NET MVC: Implement Theme Folders using a Custom ViewEngine It’s nice when you’re able to just swap out CSS files to change the theme, but this really isn’t very practical in a ton of cases. Especially when each theme needs to have … Read more

Prevent IIS from serving static files through ASP.NET pipeline

I’m taking a guess here and suspect that you have the following setting configured in your web.config file: <modules runAllManagedModulesForAllRequests=”true”> This means that every request, including those for static content is hitting the pipeline. Change this setting to: <modules runAllManagedModulesForAllRequests=”false”> This is assuming your application is running under ASP.NET 4.0 and MVC3. For this to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)