Chandra Oemaryadi has written 244 articles

ASP MVC Form Model Binding to Non-Sequential List

[code language=”html”] <form method="post" action="/Home/Create"> <input type="hidden" name="products.Index" value="cold" /> <input type="text" name="products[cold].Name" value="Beer" /> <input type="text" name="products[cold].Price" value="7.32" /> <input type="hidden" name="products.Index" value="123" /> <input type="text" name="products[123].Name" value="Chips" /> <input type="text" name="products[123].Price" value="2.23" /> <input type="hidden" name="products.Index" value="caliente" /> <input type="text" name="products[caliente].Name" value="Salsa" /> <input type="text" name="products[caliente].Price" value="1.23" /> <input type="submit" /> </form> [/code]…

ASP.NET MVC Default Route to Area

[Warning] Mengakibatkan masalah ketika memanggil @Url.Action tapi tidak ada area. Disarankan default page jangan di dalam area. Masalah ketika default page di dalam area. Controller masuk, tapi mencari view di luar area. RouteConfig.cs [code language=”csharp”] public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Default", "{controller}/{action}/{id}", new { controller = "Dashboard", action = "Index", area =…

ADO.NET Entity Framework Many-to-Many

Jika ada tabel many-to-many, dengan tabel perantara yang tidak memiliki id, perlu penanganan khusus pada DbContext. Contoh penanganan sbb: [code language=”csharp”] public class SchoolContext : DbContext { public DbSet<Course> Courses { get; set; } public DbSet<Person> People { get; set; } public SchoolContext() : base("MyDb") { } protected override void OnModelCreating(DbModelBuilder modelBuilder) { modelBuilder.Entity<Course>(). HasMany(c…

Visual Studio Debug Access from Other Computer

Assume your machine name is ‘jedi’, and your port number is ’16253′, replace appropriately. 1. Run a command prompt as administrator, and type in netsh http add urlacl url=http://jedi:16253/ user=everyone 2. Open up the following file in Notepad or Visual Studio MyDocuments\IISExpress\config\ applicationhost.config change the binding from: <binding protocol=”http” bindingInformation=”*:16253:localhost” /> to: <binding protocol=”http” bindingInformation=”*:16253:jedi”…

Visual Studio Setting

Setting Visual Studio yang cukup membantu 😀 A. Menjalankan IIS tanpa men-debug Turning off the new “Enable Edit and Continue” feature fixed it for me. Open Options dialog box (Tools | Options) Locate “Debugging\Edit and Continue” Uncheck “Enable Edit and Continue” http://stackoverflow.com/questions/19568762/how-can-i-prevent-visual-studio-2013-from-closing-my-iis-express-app-when-i-end B. Debug tanpa membuka browser Open your startup project’s properties (Project->{ProjectName} Properties… from…

Kendo Grid Column Null Value

Kendo Grid menampilkan tulisan “null” jika data dari server null. Supaya Grid menampilkan cell kosong, gunakan fungsi javascript seperti berikut [code language=”javascript”] function isnull(a, b) { b = b || ”; return a || b; } [/code] Penggunaan di Grid [code language=”javascript”] { field: "whys", title: "Isu Kunci", template: "#= isnull(KeyIssue, ”) #", }, [/code]

Bootstrap Dropdown Menu on Right Side

Bootstrap dropdown menu pada bagian kanan halaman akan mengakibatkan tampilan seperti ini: Solusi menambahkan kelas pull-right pada dropdown menu [code language=”html”] <li class=""> <a data-toggle="dropdown" href="javascript:"><span class="glyphicon glyphicon-cog"></span></a> <ul class="dropdown-menu pull-right" role="menu"> <li class="#"><a href="#">Ubah Password</a></li> <li class="#">@Html.ActionLink("Logout", "Logout", "Account")</li> </ul> </li> [/code]

ASP Read & Write File

[code language=”csharp”] public void ReadFromFile() { string fullPath = System.Web.Hosting.HostingEnvironment.MapPath(FilePath); if (System.IO.File.Exists(fullPath)) { using (StreamReader sr = File.OpenText(fullPath)) { Description = sr.ReadToEnd(); } } } public void SaveToFile() { string fullPath = System.Web.Hosting.HostingEnvironment.MapPath(FilePath); File.WriteAllText(fullPath, Description); //create / overwrite } [/code]