How to create Select List for Country and States/province in MVC

public static List<SelectListItem> States = new List<SelectListItem>() { new SelectListItem() {Text=”Alabama”, Value=”AL”}, new SelectListItem() { Text=”Alaska”, Value=”AK”}, new SelectListItem() { Text=”Arizona”, Value=”AZ”}, new SelectListItem() { Text=”Arkansas”, Value=”AR”}, new SelectListItem() { Text=”California”, Value=”CA”}, new SelectListItem() { Text=”Colorado”, Value=”CO”}, new SelectListItem() { Text=”Connecticut”, Value=”CT”}, new SelectListItem() { Text=”District of Columbia”, Value=”DC”}, new SelectListItem() { Text=”Delaware”, Value=”DE”}, new … Read more

Why can’t we add a Web API as a “service reference” in Visual Studio the same way we can with WCF or ASMX?

Do you mean a Rest Web Service? With Rest, there is no service definition page, like with WCF or ASMX. Usually people want to use a Rest API with JSON.. however.. if you are just looking for a JSON output, and you want your clients to quickly be able to connect to your service, you … Read more

Entry point was not found exception

I have converted a project from MVC3+.NET4 to MVC4+.NET4.5 and I receive the exception Entry point was not found when invoking a controller’s action. My solution was to insert an assembly binding redirect inside web.config to point at MVC 4 assemblies: <runtime> <assemblyBinding xmlns=”urn:schemas-microsoft-com:asm.v1″> <dependentAssembly> <assemblyIdentity name=”System.Web.Helpers” publicKeyToken=”31bf3856ad364e35″ /> <bindingRedirect oldVersion=”1.0.0.0-2.0.0.0″ newVersion=”2.0.0.0″ /> </dependentAssembly> <dependentAssembly> … Read more

remove required property from input field on form submit

JavaScript is case sensitive. Use document.getElementById(“city”).required = false; Demonstration Be careful that your code can’t work as you try to access the element before it exists. Put your script after the element if you don’t execute the code on an event : <input type=”text” id=”city” required> <script> if(somecondition is true){ document.getElementById(“city”).required = false; } </script> … Read more

Register global filters in ASP.Net MVC 4 and Autofac

There’s a new way of registering MVC global filters in AutoFac. First, remove the filter registration from your RegisterGlobalFilters because we will have Autofac handle adding them to our controllers/actions instead of MVC. Then, register your container as follows: var builder = new ContainerBuilder(); builder.RegisterControllers(Assembly.GetExecutingAssembly()); builder.RegisterType<MyProperty>().As<IProperty>(); builder.Register(c => new CustomFilterAttribute(c.Resolve<IProperty>())) .AsActionFilterFor<Controller>().InstancePerHttpRequest(); builder.RegisterFilterProvider(); IContainer container = … Read more

How to set debug false for release mode

Web.config transformations as they are defined in the Web.Release.config are only done when deploying/publishing the project for the relevant configuration. Just changing the active configuration in Visual Studio to Release and running the application does not run the transformations. Therefore, the web.config remains unchanged. This behavior is reasonable by the way as a web application … Read more

DelegatingHandler for response in WebApi

Yes. You can do that in the continuation task. I explain it here. For example, this code (from the blog above) traces request URI and adds a dummy header to response. public class DummyHandler : DelegatingHandler { protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { // work on the request Trace.WriteLine(request.RequestUri.ToString()); var response = … Read more

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