ASP.NET MVC 2 – Html.DropDownListFor confusion with ViewModel

I was also experiencing the same issue. When I debug the Action and look at the ModelState.Values[1].Errors[0].Exception for example, I see the following: {“The parameter conversion from type ‘System.String’ to type ‘System.Collections.Generic.KeyValuePair`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Int64, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]’ failed because no type converter can convert between these types.”} System.Exception {System.InvalidOperationException} In my scenario, … Read more

DropDownListFor does not select value if in for loop

Not sure if this is new to mv4 or if it exists in prior version. But the DropDownListFor includes an additional parameter for the SelectList Constructor. SelectList(IEnumerable, String, String, Object) For example: Html.DropDownListFor( x => x.Countries[ i ], New SelectList(Model.CountryList,”ID”,”Description”,Model.Countries[i])) Where ID is the Country ID in the CountryList object and Description is the Country … Read more

Validation: How to inject A Model State wrapper with Ninject?

The solution given by that article mixes validation logic with the service logic. These are two concerns and they should be separated. When your application grows you will quickly find out that validation logic gets complicated and gets duplicated throughout the service layer. I, therefore, like to suggest a different approach. First of all, it … Read more

.NET MVC : Calling RedirectToAction passing a model?

I don’t believe ModelBinding exists when using RedirectToAction. Your best options, however, is to use the TempData collection to store the object, and retrieve it in the following action. [AcceptVerbs(HttpVerbs.Post)] public ActionResult Add(…) { //… Kindergarten k = … TempData[“KG”] = k; return RedirectToAction(“List”); } In your List Action public ActionResult List() { Kindergarten k … Read more

MsBuild and MsDeploy with multiple environments

The first attempt failed because Package target doesn’t exist in the solution file. When using MSBuild on a solution file, a temporary MSBuild project is created (SamplePackage.sln.metaproj); this project file contains only some targets (Build, Clean, Rebuild, Publish, …) Solution : DeployOnBuild & DeployTarget properties One way to do what you want is to use … Read more

asp.net mvc convert \n new line to html breaks

The following class implements a HtmlHelper that properly encodes the text: public static class HtmlExtensions { public static MvcHtmlString Nl2Br(this HtmlHelper htmlHelper, string text) { if (string.IsNullOrEmpty(text)) return MvcHtmlString.Create(text); else { StringBuilder builder = new StringBuilder(); string[] lines = text.Split(‘\n’); for (int i = 0; i < lines.Length; i++) { if (i > 0) builder.Append(“<br/>\n”); … Read more

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