How can I supply an AntiForgeryToken when posting JSON data using $.ajax?

You don’t need the ValidationHttpRequestWrapper solution since MVC 4. According to this link. Put the token in the headers. Create a filter. Put the attribute on your method. Here is my solution: var token = $(‘input[name=”__RequestVerificationToken”]’).val(); var headers = {}; headers[‘__RequestVerificationToken’] = token; $.ajax({ type: ‘POST’, url: ‘/MyTestMethod’, contentType: ‘application/json; charset=utf-8’, headers: headers, data: JSON.stringify({ … Read more

Proper usage of .net MVC Html.CheckBoxFor

That isn’t the proper syntax The first parameter is not checkbox value but rather view model binding for the checkbox hence: @Html.CheckBoxFor(m => m.SomeBooleanProperty, new { @checked = “checked” }); The first parameter must identify a boolean property within your model (it’s an Expression not an anonymous method returning a value) and second property defines … Read more

Caching in asp.net-mvc

I like to cache in the model or data layer as well. This isolates everything to do with retrieving data from the controller/presentation. You can access the ASP.NET cache from System.Web.HttpContext.Current.Cache or use the Caching Application Block from the Enterprise Library. Create your key for the cached data from the parameters for the query. Be … Read more

How to add Date Picker Bootstrap 3 on MVC 5 project using the Razor engine?

This answer uses the jQuery UI Datepicker, which is a separate include. There are other ways to do this without including jQuery UI. First, you simply need to add the datepicker class to the textbox, in addition to form-control: <div class=”form-group input-group-sm”> @Html.LabelFor(model => model.DropOffDate) @Html.TextBoxFor(model => model.DropOffDate, new { @class = “form-control datepicker”, placeholder … Read more

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