Compile Views in ASP.NET MVC

From the readme word doc for RC1 (not indexed by google) ASP.NET Compiler Post-Build Step Currently, errors within a view file are not detected until run time. To let you detect these errors at compile time, ASP.NET MVC projects now include an MvcBuildViews property, which is disabled by default. To enable this property, open the … Read more

Passing data to a bootstrap modal

I think you can make this work using jQuery’s .on event handler. Here’s a fiddle you can test; just make sure to expand the HTML frame in the fiddle as much as possible so you can view the modal. http://jsfiddle.net/8c05pn1f/ HTML <p>Link 1</p> <a data-toggle=”modal” data-id=”ISBN564541″ title=”Add this item” class=”open-AddBookDialog btn btn-primary” href=”#addBookDialog”>test</a> <p>&nbsp;</p> <p>Link … Read more

ASP.NET MVC – Set custom IIdentity or IPrincipal

Here’s how I do it. I decided to use IPrincipal instead of IIdentity because it means I don’t have to implement both IIdentity and IPrincipal. Create the interface interface ICustomPrincipal : IPrincipal { int Id { get; set; } string FirstName { get; set; } string LastName { get; set; } } CustomPrincipal public class … Read more

Can I set an unlimited length for maxJsonLength in web.config?

NOTE: this answer applies only to Web services, if you are returning JSON from a Controller method, make sure you read this SO answer below as well: https://stackoverflow.com/a/7207539/1246870 The MaxJsonLength property cannot be unlimited, is an integer property that defaults to 102400 (100k). You can set the MaxJsonLength property on your web.config: <configuration> <system.web.extensions> <scripting> … Read more

How do you create a dropdownlist from an enum in ASP.NET MVC?

For MVC v5.1 use Html.EnumDropDownListFor @Html.EnumDropDownListFor( x => x.YourEnumField, “Select My Type”, new { @class = “form-control” }) For MVC v5 use EnumHelper @Html.DropDownList(“MyType”, EnumHelper.GetSelectList(typeof(MyType)) , “Select My Type”, new { @class = “form-control” }) For MVC 5 and lower I rolled Rune’s answer into an extension method: namespace MyApp.Common { public static class MyExtensions{ … Read more

How do you handle multiple submit buttons in ASP.NET MVC Framework?

Here is a mostly clean attribute-based solution to the multiple submit button issue based heavily on the post and comments from Maarten Balliauw. [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] public class MultipleButtonAttribute : ActionNameSelectorAttribute { public string Name { get; set; } public string Argument { get; set; } public override bool IsValidName(ControllerContext controllerContext, … Read more

File Upload ASP.NET MVC 3.0

You don’t use a file input control. Server side controls are not used in ASP.NET MVC. Checkout the following blog post which illustrates how to achieve this in ASP.NET MVC. So you would start by creating an HTML form which would contain a file input: @using (Html.BeginForm(“Index”, “Home”, FormMethod.Post, new { enctype = “multipart/form-data” })) … Read more

Html.Partial vs Html.RenderPartial & Html.Action vs Html.RenderAction

Html.Partial returns a String. Html.RenderPartial calls Write internally and returns void. The basic usage is: // Razor syntax @Html.Partial(“ViewName”) @{ Html.RenderPartial(“ViewName”); } // WebView syntax <%: Html.Partial(“ViewName”) %> <% Html.RenderPartial(“ViewName”); %> In the snippet above, both calls will yield the same result. While one can store the output of Html.Partial in a variable or return … Read more

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