LINQ to Entities does not recognize the method ‘System.String ToString()’ method in MVC 4

You got this error because Entity Framework does not know how to execute .ToString() method in sql. So you should load the data by using ToList and then translate into SelectListItem as: var query = dba.blob.ToList().Select(c => new SelectListItem { Value = c.id.ToString(), Text = c.name_company, Selected = c.id.Equals(3) }); Edit: To make it more … Read more

MVC 4 Beta side by side installation error

After installing MVC4 beta today, a few of my MVC 3 projects would not compile. (ModelClientValidationRule conflict) The fix was: Edit: ProjectName.csproj Change <Reference Include=”System.Web.WebPages”/> To <Reference Include=”System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL “/>

Enum localization

You can implement a description attribute. public class LocalizedDescriptionAttribute : DescriptionAttribute { private readonly string _resourceKey; private readonly ResourceManager _resource; public LocalizedDescriptionAttribute(string resourceKey, Type resourceType) { _resource = new ResourceManager(resourceType); _resourceKey = resourceKey; } public override string Description { get { string displayName = _resource.GetString(_resourceKey); return string.IsNullOrEmpty(displayName) ? string.Format(“[[{0}]]”, _resourceKey) : displayName; } } } … Read more

Jquery dialog partial view server side validation on Save button click

You should try unobstrusive Client side Validation Example JQuery $(‘#BTN’).click(function () { var $formContainer = $(‘#formContainer’); var url = $formContainer.attr(‘data-url’); $formContainer.load(url, function () { var $form = $(‘#myForm’); $.validator.unobtrusive.parse($form); $form.submit(function () { var $form = $(this); if ($form.valid()) { $.ajax({ url: url, async: true, type: ‘POST’, data: JSON.stringify(“Your Object or parameter”), beforeSend: function (xhr, opts) … Read more

Windows Authentication and add Authorization Roles through database – MVC asp.net

You just need to create a custom role provider. You do this by creating a class that inherits from System.Web.Security.RoleProvider and overriding certain members. The below code should get you started. Replace all the throw new NotImplementedException() stuff with your implementation of the function. For example, IsUserInRole you would provide code that would query your … Read more

the file you are trying to open is in a different format than specified by the file extension in Asp.Net

I have used CloseXML to solve the problem. public static void ExportToExcel(IEnumerable<dynamic> data, string sheetName) { XLWorkbook wb = new XLWorkbook(); var ws = wb.Worksheets.Add(sheetName); ws.Cell(2, 1).InsertTable(data); HttpContext.Current.Response.Clear(); HttpContext.Current.Response.ContentType = “application/vnd.openxmlformats-officedocument.spreadsheetml.sheet”; HttpContext.Current.Response.AddHeader(“content-disposition”, String.Format(@”attachment;filename={0}.xlsx”,sheetName.Replace(” “,”_”))); using (MemoryStream memoryStream = new MemoryStream()) { wb.SaveAs(memoryStream); memoryStream.WriteTo(HttpContext.Current.Response.OutputStream); memoryStream.Close(); } HttpContext.Current.Response.End(); } Installed ClosedXML in my project using Nuget Package … Read more

tech