Modify default ErrorMessage for StringLength validation

You can specify the StringLength attribute as follows on numerous properties [StringLength(20, ErrorMessageResourceName = “StringLengthMessage”, ErrorMessageResourceType = typeof(Resource))] public string OfficePhone { get; set; } [StringLength(20, ErrorMessageResourceName = “StringLengthMessage”, ErrorMessageResourceType = typeof(Resource))] public string CellPhone { get; set; } and add the string resource (named StringLengthMessage) in your resource file “Maximum length is {1}” Message … Read more

Can’t break in global.asax / Application_Start

Reading your question, I assume you are using IIS for debugging, not Visual Studio Development Server. In this case, debugging application start is tricky, because it is only called once when the application pool is started or recycled. When Visual Studio attaches to the process, Application_Start has already been running. The trick is to make … Read more

@Html.DropDownList width

The second argument of the DropDownList helper must be an IEnumerable<SelectListItem>. You are passing a string (an empty one to be more precise). So in order to use this helper you will have to respect its signature: @Html.DropDownList( “ListId”, Enumerable.Empty<SelectListItem>(), new { style = “width: 250px;” } ) Obviously generating an empty dropdown list is … Read more

JsonMaxLength exception on deserializing large json objects

The built-in JsonValueProviderFactory ignores the <jsonSerialization maxJsonLength=”50000000″/> setting. So you could write a custom factory by using the built-in implementation: public sealed class MyJsonValueProviderFactory : ValueProviderFactory { private static void AddToBackingStore(Dictionary<string, object> backingStore, string prefix, object value) { IDictionary<string, object> d = value as IDictionary<string, object>; if (d != null) { foreach (KeyValuePair<string, object> entry … Read more

MVC Forms LoginUrl is incorrect

This is a known issue. I had the same problem with my custom authorize attribute. I found the solution somewhere on the net, can’t remember where. Just add this to appSettings in your web.config <add key=”loginUrl” value=”~/Account/LogOn” /> Note: This works with MVC 3, I didn’t try it with previous versions. EDIT: Found it mentioned … Read more

using javascript variable in MVC3 Razor view engine

It actually is very much possible with the following: var hello = “Great Job!”; var text = “@Html.ActionLink( “Link text”, “Action Name”, new { id = “JSVar” })” text = text.replace(“JSVar”,hello); As easy as that! 🙂 All the @Html.Action link does is create a url string so doing replace on it is the same as … Read more

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