Model binding comma separated query string parameter

Here’s my improved version of Nathan Taylor’s solution used in archil’s answer. Nathan’s binder could only bind sub-properties of complex models, while mine can also bind individual controller arguments. My binder also gives you correct handling of empty parameters, by returning an actual empty instance of your array or IEnumerable. To wire this up, you … Read more

How to mix HTML and C# Code in MVC3 with Razor?

Let’s start with improving your code. Improvement step 1: @foreach(var myObj in Model.Select((model, index) => new { model, index })) { <div class=”class@(myObj.index % 2 == 0 ? “1” : “2”)”> @Html.Partial(“_Foo”, myObj.model) </div> } Improvement Step 2 (using a custom HTML helper for the class): @foreach(var myObj in Model.Select((model, index) => new { model, … Read more

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

@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

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