Model Binding to a List MVC 4

This is how I do it if I need a form displayed for each item, and inputs for various properties. Really depends on what I’m trying to do though. ViewModel looks like this: public class MyViewModel { public List<Person> Persons{get;set;} } View(with BeginForm of course): @model MyViewModel @for( int i = 0; i < Model.Persons.Count(); … Read more

How do I resolve Web API controllers using Autofac in a mixed Web API and MVC application?

I would suggest the following to make this work in your application with both MVC and WebApi. First your project will need to have references to the following Autofac Autofac.WebApi Autofac.Mvc5 (change the number at the end to match your aspnet mvc version) Then in your Autofac registration you would need the following which will … Read more

Could not load file or assembly Exception from HRESULT: 0x80131040

Finally found the answer!! Go to References –> right cilck on dll file that causing the problem –> select the properties –> check the version –> match the version in properties to web config <dependentAssembly> <assemblyIdentity name=”YourDllFile” publicKeyToken=”2780ccd10d57b246″ culture=”neutral” /> <bindingRedirect oldVersion=”0.0.0.0-YourDllFileVersion” newVersion=”YourDllFileVersion” /> </dependentAssembly>

ASP.NET MVC 4 Mobile Features

ASP.Net (actually the HttpBrowserCapabilitiesBase class) doesn’t recognize the Opera Mobile Emulator as a Mobile browser. You can check this in any controller action: HttpContext.Request.Browser.IsMobileDevice will return false for the Opera Mobile browser. Because the built in DefaultDisplayMode uses the following method to check mobile browsers you need to register your custom DisplayMode which correctly recognizes … Read more

client-side validation in custom validation attribute – asp.net mvc 4

Take a look at this: http://thewayofcode.wordpress.com/tag/custom-unobtrusive-validation/ Using this tutorial I got my custom validation code running with no problem. The only difference I can spot in your code is the way you created the $.validator.unobtrusive.adapters.add function. The parameters are a little bit different but, maybe, the problem is just that you have not defined the … Read more

How to specify ContentType for Web API controller method

You’ll have to change the return type of the method to HttpResponseMessage, then use Request.CreateResponse: // GET api/Audit/CSV [HttpGet, ActionName(“CSV”)] public HttpResponseMessage Csv(Guid sessionId, DateTime a, DateTime b, string predicate) { var result = new StringBuilder(); //build a string var res = Request.CreateResponse(HttpStatusCode.OK); res.Content = new StringContent(result.ToString(), Encoding.UTF8, “text/csv”); return res; }

How to get GET parameters with ASP.NET MVC ApiController

The ApiController is designed to work without the HttpContext object (making it portable, and allowing it to be hosted outside of IIS). You can still access the query string parameters, but it is done through the following property: Request.GetQueryNameValuePairs() Here’s an example loop through all the values: foreach (var parameter in Request.GetQueryNameValuePairs()) { var key … Read more

mvc4 data annotation compare two dates

Take a look at Fluent Validation or MVC Foolproof Validation: those can help you a lot. With Foolproof for example there is a [GreaterThan(“StartDate”)] annotation than you can use on your date property. Or if you don’t want to use other libraries, you can implement your own custom validation by implementing IValidatableObject on your model: … Read more

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