August 2012 | Coding Cluster - using, c#, mvc 4, iphone, php, ios, javascript, in mvc 3 & more

ASP.NET MVC 4 - Solution: The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_Layout.cshtml": "Class". or "Scripts"


ASP.Net MVC 4 Razor: Section Defined But Not Rendered Error:
                            In mvc 4 project development  you may face an error like "The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_Layout.cshtml": "Class". and / or "The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_Layout.cshtml": "scripts".

It means that you have no definition for  a section in your master Layout.cshtml, but you try to get that section from your View. To resolve this problem, check your view.cshtml has some thing like this

@section Class{

and / or

@section scripts{

If yes, you must define a section in your master Layout.cshtml like this
To fix this section defined but bot rendered error you just add this lines before the end of body tag in your Layout.cshtml

 @RenderSection("scripts", required: false)

 @RenderSection("Class", required: false)

Please share this post if it's useful to you. Thanks!.

iphone: Step by step guide to Publish the app to app store by iTunes Connect


Here is the detailed report on Publishing the iPhone application into iTunes connect.

  1. Login into using Apple ID and Password.
  2. Click Manage Your App from iTunes Connect.
  3. Click the Add New App button to start the process of creating a new iTunes App.
  4. Here it'll ask some basic information about the application such as Company Name, App Name, SKU ID, Bundle ID.
  5. Just make sure that your Bundle ID should match with your info.plist.
  6. Finally need to upload the large size app image with 512 X 512 px. and screenshot of the application with 960 X 640 px and click the Save button.
  7. Now click the View Details button under Versions.
  8. Here click the Ready to Upload Binary button and finish the process. Now the status of the application is Waiting for Upload
  9. Now go to Xcode and choose iOS Device in the schema chooser. Then choose the "Archive" under the "Product"  menu.
  10. Now Xcode will open the Organizer window with the app in Archive tab. Here we can Validate and Distribute the app.
  11. Now the status of the app is Upload Received. After few minutes it'll change to Waiting For Review.
Please share this post if it's useful to you. Thanks!.

Source: How to create a drop down list in mvc4


Bind data to dropdownlist in MVC4:

           This is the basic code for creating a page with a dropdown.

The difference between clasic web forms and mvc is that mvc doesn't have those events like "selectedIndexChanged", because all the controls are pure html controls.

// in view page model

 public class DropdownViewModel
        public SelectList ProductList { get; set; }

// in controller action 

   public ActionResult Create()
            DropdownViewModel model = new DropdownViewModel();

            List<SelectListItem> listItems = new List<SelectListItem>();
            listItems.Add(new SelectListItem()
                Value = "1",
                Text = "Product 1"
            listItems.Add(new SelectListItem()
                Value = "2",
                Text = "Product 2"
            listItems.Add(new SelectListItem()
                Value = "3",
                Text = "Product 3"
            listItems.Add(new SelectListItem()
                Value = "4",
                Text = "Product 4"
            listItems.Add(new SelectListItem()
                Value = "5",
                Text = "Product 5"
            model.ProductList = new SelectList(listItems, "Value", "Text");

            return View(model);

//And finally this is in view page 

@model YourApplication.Models.DropdownViewModel
 @Html.DropDownList("product", Model.ProductList)

And this is the output of the above code

Avoid jQuery conflict with Other JavaScript library(prototype,YUI,mootools)

Avoid jquery conflict with other javascript libraries:
                  In this jQuery article, I will explain how to avoid jquery conflict with other javascript libraries.

javascript libraries such as YUI, prototype conflict with Jquery library as prototype library also uses `$` sign.To resolve this issue, jQuery has .noConflict() method.

.noConflict() method: Relinquish jQuery's control of the $ variable (override the $ function)
we can avoid prototype and jquery conflict using .noConflict() method.


<title>Avoid conflict between JQuery and prototype,YUI,mootools (Other javascript Libraries)</title>
    <script src="/js/prototype.js"></script>  
    <script src="/js/jquery.js"></script>  
<script type="text/javascript" src="../other_lib.js"></script>
<script language="javascript" type="text/javascript">  
 // Do something with jQuery
  // Do something with prototype

.NET Framework: Csharp(C#) Equivalents of SQL Server 2005 DataTypes


SQL Server Data Types and Their .NET Framework (c#) Equivalents:
                    The following table lists Microsoft SQL Server data types, their equivalents in the common language runtime (CLR) for SQL Server in the System.Data.SqlTypes namespace, and their native CLR equivalents in the Microsoft .NET Framework.

SQL Server data type CLR data type (SQL Server) CLR data type (.NET Framework)
varbinary SqlBytes, SqlBinary Byte[]
binary SqlBytes, SqlBinary Byte[]
varbinary(1), binary(1) SqlBytes, SqlBinary byte, Byte[]
image NoneNone
varchar NoneNone
char NoneNone
nvarchar(1), nchar(1) SqlChars, SqlString Char, String, Char[]
nvarchar SqlChars, SqlString
SQLChars is a better match for
data transfer and access,
and SQLString is a better match for
performing String operations.
String, Char[]
nchar SqlChars, SqlString String, Char[]
text NoneNone
ntext NoneNone
uniqueidentifier SqlGuid Guid
rowversion NoneByte[]
bit SqlBoolean Boolean
tinyint SqlByte Byte
smallint SqlInt16 Int16
int SqlInt32 Int32
bigint SqlInt64 Int64
smallmoney SqlMoney Decimal
money SqlMoney Decimal
numeric SqlDecimal Decimal
decimal SqlDecimal Decimal
real SqlSingle Single
float SqlDouble Double
smalldatetime SqlDateTime DateTime
datetime SqlDateTime DateTime
sql_variant NoneObject
User-defined type(UDT) NoneSame class that is bound to the
user-defined type in the same assembly
or a dependent assembly.
table NoneNone
cursor NoneNone
timestamp NoneNone
xml SqlXml None
For more details please review this link

Create a Foreign Key relationship using Code First Entity Framework and MVC4


Entity Framework Code First: Add a Foreign Key relationship in MVC 4:

When building an single page application in MVC4 using Entity Framework Code First you might run into the following exception:

Unable to retrieve association information for association 'Models.Product_Parent'. Only models that include foreign key information are supported. See Entity Framework documentation for details on creating models that include foreign key information.

This is due to the way you've defined the relation ships in the dbContext. Lets say me have a dbContextcontaining products which can have child products, you would write the following code:

public class Product
    public int Id { get; set; }
    public string Name { get; set; }
    public virtual Product Parent { get; set; }
public class ProductContext : DbContext
    public DbSet<product> Products { get; set; }

This should be enough to let EF know there is a relationship in there, but sadly it's not. We can solving this by following way:

we can create an extra property ParentId give this a ForeighKeyAttribute that links it to the Parent property.

public int? ParentId { get; set; }
public virtual Product Parent { get; set; }

Download ASP.NET MVC 4: insert, edit, update, delete with sql server using csharp (c#)


Select, Insert, Update And Delete With ASP.NET MVC 4 and SQL server database using C#:
                                         In one of my previous article I'm explained how to create a sample project with mvc 4?. In this article we look at how to do insert, edit, update, delete with  sql server database using csharp.

Getting Started with MVC4 wep application with sql server databas:
                           Here you can only download a sample mvc 4 project with sql server. And all the other steps like create models, controllers, views, insert, update, delete etc.. you can find Rick Anderson's article from .
I think this is a best tutorial for your first mvc 4 project.

 I'm created the above project just followed by Rick Anderson' articles.

Issue with Connection string in mvc 4:
  If you face any problem with your default connection string (when change the data storage from .mdf to sql server). You just change your connection string with the following format.

code to resolve database connection string problems in mvc 4:

 <add name="MovieDBContext" connectionString="data source=localhost;uid=sa;pwd=sa;Initial Catalog=MyFirstMVC" providerName="System.Data.SqlClient" />

 And you can download the mvc 4 web application with insert, edit, update, delete in sql server data base  source code from here.

Don't forgot to share this knowledge to your friends. Cheers!

iphone sdk: get / retrieve/ display all first name and last names from the address book

iPhone-  Retrive contact list name from default Address Book:
                      This tips demonstrates how to print the first and last names for all entries in the iPhone Address Book to the console. Start by including the following import statement:

#import <AddressBook/AddressBook.h>

Also, add the AddressBook.framework to your project.
To display all the address book names, create an address book reference, copy all entries into an array and for each entry, access the first and last name properties.


ABAddressBookRef addressBook = ABAddressBookCreate();
// Can we find the address book...
if (addressBook != nil)
  // Get an array address book entries
  CFArrayRef arrayOfEntries = ABAddressBookCopyArrayOfAllPeople(addressBook);
  // Are there entries in the array?
  if (CFArrayGetCount(arrayOfEntries) > 0)
    CFIndex countOfEntries = CFArrayGetCount(arrayOfEntries);
    NSLog(@"Address book entries: %ld", countOfEntries);
    for (int x = 0; x < countOfEntries ; x++)
      // Get the current entry
      ABRecordRef activeRecord = CFArrayGetValueAtIndex(arrayOfEntries, x);
      // Print first name
      NSString *firstname = (NSString *) ABRecordCopyValue(activeRecord, kABPersonFirstNameProperty);
      NSLog(@"First name: %@", firstname);
      [firstname release];
      // Print last name        
      NSString *lastname = (NSString *) ABRecordCopyValue(activeRecord, kABPersonLastNameProperty);
      NSLog(@"Last name: %@", lastname);
      [lastname release];

iPhone tricks:Insert string value with single quotes ( Replace single quote in sqlite3 insert query - objective c ) in iphone sdk


                                             I am working in SQLite3 database for Iphone App.In Objecitve-c one of my query is getting failed because of the value "This is user's profile" as it contains single quote. So I'm using the following solution to resolve my problem. By using the string replacement we can save the apostrophe into the database. Look at the following sample

strAddress =  [strAddress stringByReplacingOccurrencesOfString:@"'" withString:@"\''"];

How to programmatically prevent iphone auto-lock?
                            Simply disabled the idle timer to prevent outo-lock the iphone while your app is open. Just add the following line into your apps delegate.m file.

- (void)applicationDidFinishLaunching:(UIApplication *)application {   application.idleTimerDisabled = YES;  }

How to hide keyboard when you press the button - iphone sdk?
           In button action you just write

 [yourTextField resignFirstResponder].

It will hide your keyboard.

How to take a screenshot with the iPhone?
                 To take a screenshot, hold the home button and click the sleep button. The screen will flash white and the screenshot will be stored in your camera roll.




Blogger Widgets